当前位置: 首页>>代码示例>>PHP>>正文


PHP PassHash类代码示例

本文整理汇总了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;
}
开发者ID:danaucpe,项目名称:bravecollective-intel,代码行数:29,代码来源:auth.php

示例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'];
     }
 }
开发者ID:boycaught,项目名称:dokuwiki,代码行数:22,代码来源:auth.php

示例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.'));
     }
 }
开发者ID:pramana08,项目名称:GXC-CMS-2,代码行数:27,代码来源:UserUpdateWidget.php

示例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;
 }
开发者ID:karimyasser91,项目名称:EKTechnologies,代码行数:35,代码来源:DbHandler.php

示例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;
     }
 }
开发者ID:amakaroff82,项目名称:mimi,代码行数:32,代码来源:DbHandler.php

示例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;
 }
开发者ID:UFOkechukwu,项目名称:SocialLoginForiOS,代码行数:31,代码来源:OAuthHelper.php

示例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);
     }
 }
开发者ID:pramana08,项目名称:GXC-CMS-2,代码行数:29,代码来源:UserChangePassWidget.php

示例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'));
 }
开发者ID:rsnitsch,项目名称:dokuwiki,代码行数:11,代码来源:PassHash.test.php

示例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;
     }
 }
开发者ID:pramana08,项目名称:GXC-CMS-2,代码行数:20,代码来源:UserChangePassForm.php

示例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;
 }
开发者ID:AmrN,项目名称:Event-Sched---PHP,代码行数:20,代码来源:DbHandler.php

示例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;
 }
开发者ID:pramana08,项目名称:GXC-CMS-2,代码行数:52,代码来源:UserIdentityDb.php

示例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;
     }
 }
开发者ID:TrienDo,项目名称:BestBooks,代码行数:24,代码来源:UserService.php

示例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;
     }
 }
开发者ID:oliveirawro,项目名称:BDR,代码行数:20,代码来源:DbHandler.php

示例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'));
     }
 }
开发者ID:nhattrungluu,项目名称:laravel,代码行数:27,代码来源:UserController.php

示例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;
     }
 }
开发者ID:ZillaScylla,项目名称:slim-rest,代码行数:27,代码来源:DbHandler.php


注:本文中的PassHash类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。