本文整理汇总了PHP中PassHash类的典型用法代码示例。如果您正苦于以下问题:PHP PassHash类的具体用法?PHP PassHash怎么用?PHP PassHash使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了PassHash类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: authUploaderToken
function authUploaderToken()
{
global $dbr, $cfg_expire_uploader;
$user = authCheck();
if ($user === false) {
return false;
}
$stm = $dbr->prepare('SELECT * FROM uploader WHERE charId = :charId;');
$stm->bindValue(':charId', $user[0]);
if (!$stm->execute()) {
die('sql error');
}
$row = $stm->fetch();
if ($row) {
return $row['sessionId'];
}
require 'PassHash.class.php';
$ph = new PassHash();
$token = $ph->gen_salt(32);
$stm = $dbr->prepare('INSERT INTO uploader (charId, charName, sessionId, createdAt) VALUES (:charId, :charName, :sessionId, :createdAt);');
$stm->bindValue(':charId', $user[0]);
$stm->bindValue(':charName', $user[1]);
$stm->bindValue(':sessionId', $token);
$stm->bindValue(':createdAt', time());
if (!$stm->execute()) {
die('sql error');
}
return $token;
}
示例2: checkPass
/**
* Check user+password
*
* @param string $user the user name
* @param string $pass the clear text password
* @return bool
*/
public function checkPass($user, $pass)
{
$data = $this->_selectUser($user);
if ($data == false) {
return false;
}
if (isset($data['hash'])) {
// hashed password
$passhash = new PassHash();
return $passhash->verify_hash($pass, $data['hash']);
} else {
// clear text password in the database O_o
return $pass == $data['clear'];
}
}
示例3: renderContent
protected function renderContent()
{
$user_id = isset($_GET['id']) ? (int) $_GET['id'] : 0;
if ($user_id !== 0) {
$model = User::model()->findbyPk($user_id);
$old_pass = (string) $model->password;
// if it is ajax validation request
if (isset($_POST['ajax']) && $_POST['ajax'] === 'userupdate-form') {
echo CActiveForm::validate($model);
Yii::app()->end();
}
// collect user input data
if (isset($_POST['User'])) {
$model->attributes = $_POST['User'];
if ($model->password != $old_pass) {
$model->password = PassHash::hash($model->password);
}
$model->scenario = 'update';
if ($model->save()) {
user()->setFlash('success', t('cms', 'Updated Successfully!'));
}
}
$this->render('cmswidgets.views.user.user_update_widget', array('model' => $model));
} else {
throw new CHttpException(404, t('cms', 'The requested page does not exist.'));
}
}
示例4: createUser
/**
* Creating new user
* @param String $name User full name
* @param String $email User login email id
* @param String $password User login password
*/
public function createUser($name, $email, $password, $first_name, $last_name, $date_of_birth, $role, $gender, $city)
{
require_once 'PassHash.php';
$response = array();
// First check if user already existed in db
if (!$this->isUserExists($email)) {
// Generating password hash
$password_hash = PassHash::hash($password);
// Generating API key
$api_key = $this->generateApiKey();
// insert query
$stmt = $this->conn->prepare("INSERT INTO users(username, email, password,first_name,last_name,Date_of_birth,role,gender,city) values(?, ?, ?, ?, ?,?,?,?,?)");
$stmt->bind_param("sssssssss", $name, $email, $password_hash, $first_name, $last_name, $date_of_birth, $role, $gender, $city);
$result = $stmt->execute();
$stmt->close();
// Check for successful insertion
if ($result) {
// User successfully inserted
return USER_CREATED_SUCCESSFULLY;
} else {
// Failed to create user
return USER_CREATE_FAILED;
}
} else {
// User with same email already existed in the db
return USER_ALREADY_EXISTED;
}
return $response;
}
示例5: checkLogin
/**
* Checking user login
* @param String $email User login email id
* @param String $password User login password
* @return boolean User login status success/fail
*/
public function checkLogin($email, $password)
{
// fetching user by email
$stmt = $this->conn->prepare("SELECT password_hash FROM users WHERE email = ?");
$stmt->bind_param("s", $email);
$stmt->execute();
$stmt->bind_result($password_hash);
$stmt->store_result();
if ($stmt->num_rows > 0) {
// Found user with the email
// Now verify the password
$stmt->fetch();
$stmt->close();
if (PassHash::check_password($password_hash, $password)) {
// User password is correct
return TRUE;
} else {
// user password is incorrect
return FALSE;
}
} else {
$stmt->close();
// user not existed with the email
return FALSE;
}
}
示例6: createUserByUsernameAndPassword
/**
* Creating new user via Email
* @param String $name User full name
* @param String $password User login password
*/
public function createUserByUsernameAndPassword($name, $password)
{
require_once 'PassHash.php';
$response = array();
// First check if user already existed in db
if (!$this->userExistsByEmail($email)) {
// Generating password hash
$password_hash = PassHash::hash($password);
// here you would generate other user's properties, like alias
// default avatar, api_key for authentication, and insert it in the DB.
$usercreationsucceed = true;
// Check for successful insertion
if ($usercreationsucceed) {
// User successfully inserted
// here you should return USER_CREATED_SUCCESSFULLY;
return "user created with name: " . $name . ", password: " . $password;
} else {
// Failed to create user
return USER_CREATION_FAILED;
}
} else {
// User with same email already existed in the db
return USER_ALREADY_EXISTED;
}
return $response;
}
示例7: renderContent
protected function renderContent()
{
if (!user()->isGuest) {
$model = new UserChangePassForm();
// if it is ajax validation request
if (isset($_POST['ajax']) && $_POST['ajax'] === 'userchangepass-form') {
echo CActiveForm::validate($model);
Yii::app()->end();
}
// collect user input data
if (isset($_POST['UserChangePassForm'])) {
$model->attributes = $_POST['UserChangePassForm'];
// validate user input password
if ($model->validate()) {
$u = User::model()->findbyPk(user()->id);
if ($u !== null) {
$u->password = PassHash::hash($model->new_password_1);
if ($u->save()) {
user()->setFlash('success', t('cms', 'Changed Password Successfully!'));
}
}
$model = new UserChangePassForm();
}
}
$this->render('cmswidgets.views.user.user_change_pass_widget', array('model' => $model));
} else {
Yii::app()->request->redirect(user()->returnUrl);
}
}
示例8: test_hmac
function test_hmac()
{
// known hashes taken from https://code.google.com/p/yii/issues/detail?id=1942
$this->assertEquals('df08aef118f36b32e29d2f47cda649b6', PassHash::hmac('md5', 'data', 'secret'));
$this->assertEquals('9818e3306ba5ac267b5f2679fe4abd37e6cd7b54', PassHash::hmac('sha1', 'data', 'secret'));
// known hashes from https://en.wikipedia.org/wiki/Hash-based_message_authentication_code
$this->assertEquals('74e6f7298a9c2d168935f58c001bad88', PassHash::hmac('md5', '', ''));
$this->assertEquals('fbdb1d1b18aa6c08324b7d64b71fb76370690e1d', PassHash::hmac('sha1', '', ''));
$this->assertEquals('80070713463e7749b90c2dc24911e275', PassHash::hmac('md5', 'The quick brown fox jumps over the lazy dog', 'key'));
$this->assertEquals('de7c9b85b8b78aa6bc8a7a36f70a90701c9db4d9', PassHash::hmac('sha1', 'The quick brown fox jumps over the lazy dog', 'key'));
}
示例9: checkOldPass
/**
* Check the old pass is Ok or not
*
* @param array $attribute
* @param array $params
* @return boolean
*/
public function checkOldPass($attribute, $params)
{
$u = User::model()->findbyPk(user()->id);
if ($u != null) {
if (!PassHash::authenticate($this->old_password, $u->password)) {
$this->addError($attribute, t('cms', 'Old password is not correct!'));
return false;
}
} else {
$this->addError($attribute, t('cms', 'No User Found!'));
return false;
}
}
示例10: checkLogin
/**
* Checking user login
* @param String $email User login email id
* @param String $password User login password
* @return boolean User login status success/fail
*/
public function checkLogin($email, $password)
{
// fetching user by email
$stmt = $this->conn->prepare("SELECT `password_hash` FROM `users` WHERE `email` = :email");
$stmt->execute(array('email' => $email));
if ($stmt->rowCount() > 0) {
$password_hash = $stmt->fetchColumn();
if (PassHash::check_password($password_hash, $password)) {
// User password is correct
return TRUE;
}
}
return FALSE;
}
示例11: authenticate
/**
* This function check the user Authentication
*
* @return int
*/
public function authenticate()
{
// Check username based on email or username
$username = strtolower($this->username);
if (strpos($username, '@') !== false) {
$user = User::model()->find('LOWER(email)=?', array($username));
} else {
$user = User::model()->find('LOWER(username)=?', array($username));
}
if ($user === null) {
$this->errorCode = self::ERROR_USERNAME_INVALID;
} else {
if (!PassHash::authenticate($this->password, $user->password)) {
$this->errorCode = self::ERROR_PASSWORD_INVALID;
} else {
if ($user->status == ConstantDefine::USER_STATUS_ACTIVE) {
$this->_id = $user->user_id;
$this->username = $user->username;
//If the site allow auto Login, create token to recheck for Cookies
if (Yii::app()->user->allowAutoLogin) {
$autoLoginToken = sha1(uniqid(mt_rand(), true));
$this->setState('autoLoginToken', $autoLoginToken);
$connection = Yii::app()->db;
//delete old keys
$command = $connection->createCommand('DELETE FROM {{autologin_tokens}} WHERE user_id=:user_id');
$command->bindValue(':user_id', $user->user_id, PDO::PARAM_STR);
$command->execute();
//set new
$command = $connection->createCommand('INSERT INTO {{autologin_tokens}}(user_id,token) VALUES(:user_id,:token)');
$command->bindValue(':user_id', $user->user_id, PDO::PARAM_STR);
$command->bindValue(':token', $autoLoginToken, PDO::PARAM_STR);
$command->execute();
}
//Start to set the recent_login time for this user
$user->recent_login = time();
$user->save();
//Set additional User Information
//Set the Error Code to None for Success
$this->errorCode = self::ERROR_NONE;
} else {
$this->errorCode = ConstantDefine::USER_ERROR_NOT_ACTIVE;
}
}
}
unset($user);
return $this->errorCode;
}
示例12: checkLogin
/**
* Checking user login
* @param String $email User login email id
* @param String $password User login password
* @return boolean User login status success/fail
*/
public static function checkLogin($email, $password)
{
// fetching user by email
$user = User::where('email', $email)->get();
if ($user->count() > 0) {
$password_hash = $user[0]->password;
if (PassHash::check_password($password_hash, $password)) {
//Generate new API everytime log in so old API become invalid
$user[0]->apiKey = Utils::generateApiKey();
$user[0]->save();
return $user[0];
} else {
return NULL;
}
} else {
return NULL;
}
}
示例13: checkLogin
public function checkLogin($email, $password)
{
$stmt = $this->conn->prepare("SELECT password_hash FROM users WHERE email = ?");
$stmt->bind_param("s", $email);
$stmt->execute();
$stmt->bind_result($password_hash);
$stmt->store_result();
if ($stmt->num_rows > 0) {
$stmt->fetch();
$stmt->close();
if (PassHash::check_password($password_hash, $password)) {
return TRUE;
} else {
return FALSE;
}
} else {
$stmt->close();
return FALSE;
}
}
示例14: update
/**
* Update the specified resource in storage.
*
* @param Request $request
* @param int $id
* @return Response
*/
public function update(Request $request, $id)
{
//
$user = User::find($id);
if ($user) {
if ($request->get('password')) {
$user->pass_hash = PassHash::hash($request->get('password'));
}
if ($request->get('email')) {
$user->email = $request->get('email');
}
if ($request->get('sdt')) {
$user->sdt = $request->get('sdt');
}
$user->save();
return response()->json(array('error' => false, 'message' => 'User Updated'));
} else {
return response()->json(array('error' => true, 'message' => 'User Not Found'));
}
}
示例15: checkLogin
/**
* Checking user login
* @param String $email User login email id
* @param String $password User login password
* @return boolean User login status success/fail
*/
public function checkLogin($email, $password)
{
// fetching user by email
$stmt = $this->db->prepare("SELECT password_hash FROM users WHERE email = :email");
$stmt->execute(array(":email" => $email));
if ($stmt->rowCount() > 0) {
// Found user with the email
// Now verify the password
$res = $stmt->fetch();
if (PassHash::check_password($res->password_hash, $password)) {
// User password is correct
return TRUE;
} else {
// user password is incorrect
return FALSE;
}
} else {
// user not existed with the email
return FALSE;
}
}