您的位置:首页 > 编程语言 > PHP开发

php 存储密码并加密

2017-03-27 10:53 1341 查看
//设置cookie
public function auth(){
cookie('user_id',$this->user_id);
cookie('username',$this->username);
cookie('ccode', encCookie($this->user_id,$this->username));
}
//收回权限revoke()
public function revoke(){
cookie('user_id',null);
cookie('username',null);
cookie('ccode', null);
}
//密码验证
public function checkPass($password){
$sqpass=$this->password;
$this->password=$password;
$this->encPass();

return  $sqpass===$this->password;

}

public function reg(){//添加到数据库
$this->encPass();
return $this->add();
}
public function encPass(){//md5加密
$this->salt();
$this->password=md5($this->salt.$this->password);
}
public function salt(){//获取盐
if(!isset($this->salt)){//密码验证时取出的有盐,此时不需要再获取随机的盐
$this->salt= $this->randstr();
}
return $this->salt;
}
public function randstr($length=6){
$str='zxcvbnmasdfghjklqwertyuiopQWERTYUIOPASDFGHJKLZXCVBNM;}[]{()><$@0123456789';
$str=str_shuffle($str);
return substr($str,0,$length);
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: