//设置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); }
php 存储密码并加密
最新推荐文章于 2022-07-16 23:46:43 发布