本文整理匯總了PHP中Help::fetchSalt方法的典型用法代碼示例。如果您正苦於以下問題:PHP Help::fetchSalt方法的具體用法?PHP Help::fetchSalt怎麽用?PHP Help::fetchSalt使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Help
的用法示例。
在下文中一共展示了Help::fetchSalt方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: register
/**
* 注冊方法
* 完成數據的插入
* @return boolean whether register is successful
*/
public function register()
{
//將已經驗證成功的數據插入數據庫
if (!$this->hasErrors()) {
$user = new Users();
$user->username = $this->username;
$user->email = $this->email;
$user->salt = Help::fetchSalt();
$user->password = md5(md5($this->password) . $user->salt);
$user->reg_ip = Yii::app()->request->userHostAddress;
$user->last_ip = Yii::app()->request->userHostAddress;
$user->reg_time = time();
$user->last_login = time();
if (!$user->save()) {
return false;
}
}
//實行登入操作
if ($this->_identity === null) {
$this->_identity = new UserIdentity($this->email, $this->password);
$this->_identity->authenticate();
}
if ($this->_identity->errorCode === UserIdentity::ERROR_NONE) {
Yii::app()->user->login($this->_identity);
return true;
} else {
return false;
}
}
示例2: actionCheckAccount
/**
* 更改賬戶信息
*/
public function actionCheckAccount()
{
//var_dump($_POST);
//exit();
if (!Yii::app()->request->isPostRequest) {
$this->error('一定是你的提交方式不對');
}
$data = array();
if (!isset($_POST['username']) || !isset($_POST['sex']) || !isset($_POST['email'])) {
$this->error('相關字段不能為空');
}
$data['username'] = $_POST['username'];
$data['sex'] = $_POST['sex'];
$data['mobile'] = $_POST['mobile'];
//判斷用戶名是否已經存在
if (Users::model()->exists('uid <> :uid AND username=:username', array(':uid' => Yii::app()->user->id, ':username' => $data['username']))) {
$this->error('用戶名已經存在');
return;
}
//判斷是否需要改密碼
if ($_POST['old_password'] != '' && $_POST['re_password'] != '' && $_POST['password'] != '') {
//密碼長度不能小於4
if (strlen($_POST['password']) < 4) {
$this->error('密碼長度不能小於4');
}
//判斷兩次密碼輸入是否正確
if ($_POST['password'] != $_POST['re_password']) {
$this->error('兩次密碼輸入不相同');
}
//判斷初始密碼是否正確
$user = Users::model()->find('uid=? AND password=MD5(CONCAT(MD5(?),`salt`))', array(Yii::app()->user->id, $_POST['old_password']));
if (!$user) {
$this->error('初始密碼輸入不正確!');
}
//可以更新密碼
$data['salt'] = Help::fetchSalt();
$data['password'] = md5(md5(trim($_POST['password'])) . $data['salt']);
}
//頭像更新
//更新頭像
$image = Help::uploadAvatar(Yii::app()->user->id, 'avatar');
if ($image) {
$data['avatar_file'] = $image;
//更新頭像session
//
}
if (false !== Users::model()->updateByPk(Yii::app()->user->id, $data)) {
//更新 userInfo 信息
$user = Users::model()->findByPk(Yii::app()->user->id);
Yii::app()->user->setState('userInfo', $user);
$this->success('更新成功');
}
}
示例3: actionCheckAdd
/**
* 處理添加用戶
*/
public function actionCheckAdd()
{
if (!Yii::app()->request->isPostRequest) {
$this->error('一定是您的訪問方式不對');
}
//var_dump($_POST);
//判斷用戶名或email是否已經存在
if (Users::model()->exists('username=? or email=?', array($_POST['username'], $_POST['email']))) {
$this->error('用戶名或密碼已經存在!');
}
//首先插入數據獲取uid
$user = new Users();
$user->username = $_POST['username'];
$user->email = $_POST['email'];
//生日更新
$birthday = $_POST['birthday'];
$year = substr($birthday, 0, 4);
$month = substr($birthday, 5, 2);
$day = substr($birthday, 8, 2);
$user->birthday = mktime(0, 0, 0, $month, $day, $year);
$user->mobile = $_POST['mobile'];
$user->sex = $_POST['sex'];
$user->salt = Help::fetchSalt();
$user->password = md5(md5($_POST['password']) . $user->salt);
$user->reg_time = time();
$user->reg_ip = Yii::app()->request->userHostAddress;
$user->last_login = time();
$user->last_ip = Yii::app()->request->userHostAddress;
if ($user->save()) {
$this->success('添加成功!');
} else {
$this->error(var_dump($user->errors));
}
}