setPassword($password); $this->setEncrypt($encrypt); } /** * 创建对象 * @param string $password * @param string $encrypt * @return PassServer */ static function creatServer($password = '', $encrypt = '') { return new PassServer($password, $encrypt); } /** * @return string */ public function getPassword(): string { return $this->password; } /** * @param string $password */ public function setPassword($password = ''): void { if (!empty($password)) $this->password = $password; } /** * @return string */ public function getEncrypt(): string { return $this->encrypt; } /** * @param string $encrypt */ public function setEncrypt($encrypt = ''): void { if (!empty($encrypt)) $this->encrypt = $encrypt; } private $encrypt = ''; /** * @return string */ public function getErrorMsg(): string { return $this->errorMsg; } /** * 加密字符串 * @param $length * @return null|string */ public function getRandChar($length = 6) { $str = null; $strPol = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz"; $max = strlen($strPol) - 1; for ($i = 0; $i < $length; $i++) { $str .= $strPol[rand(0, $max)];//rand($min,$max)生成介于min和max两个数之间的一个随机整数 } return $str; } /** * 创建会员密码 * @return array|false */ function creatPassword() { if (empty($this->password)) { $this->errorMsg = "密码不能为空"; return false; } if (empty($this->encrypt)) $this->encrypt = $this->getRandChar(); $password = $this->memberPassword(); return ['password' => $password, 'encrypt' => $this->encrypt]; } /** * 验证密码 * @param $member_pass * @return bool */ public function verifyPass($member_pass) { $str = $this->memberPassword(); return $member_pass == $str; } /** * 密码加密 * @return string */ private function memberPassword() { $str = md5($this->password) . md5($this->encrypt); return md5($str); } /** * 生成会员登录token * @param $m_id * @return string */ public function getMemberToken($m_id) { $token = md5($m_id . 'token' . time()); return $token; } }