<?php
// 应用公共文件
/**
* 生成随机字符串
* @param string $length 长度
* @return string 字符串
*/
function create_randomstr($length = 6)
{
//字符组合
$str = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
$len = strlen($str)-1;
$randstr = '';
for ($i=0;$i<$length;$i++) {
$num = mt_rand(0,$len);
$randstr .= $str[$num];
}
return $randstr;
}
/**
* 密码加盐
* @param string $password 密码字符串
* @param string $encrypt 盐字符串
* @return array 数组
*/
function salting($password,$salt=''){
$pwd = array();
$pwd['salt'] = $salt ? $salt : create_randomstr();
$pwd['password'] = md5(md5(trim($password)).$pwd['salt']);
return $pwd;
}