本文整理汇总了PHP中DBUtils::hashPassword方法的典型用法代码示例。如果您正苦于以下问题:PHP DBUtils::hashPassword方法的具体用法?PHP DBUtils::hashPassword怎么用?PHP DBUtils::hashPassword使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DBUtils
的用法示例。
在下文中一共展示了DBUtils::hashPassword方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: signIn
/**
* sign in
* @param string $username
* @param string $password
* @return boolean
*/
public function signIn($username, $password)
{
$pdo = MySQLUtil::getConnection();
// hash the password
$password = DBUtils::hashPassword($password);
$tsql = "SELECT ur.name AS user_role, u.* FROM users AS u";
$tsql .= " INNER JOIN user_roles AS ur ON (ur.id = u.user_role_id)";
$tsql .= " WHERE u.username = :username AND u.password = :pass";
$stmt = $pdo->prepare($tsql);
$stmt->bindParam(':username', $username, PDO::PARAM_STR);
$stmt->bindParam(':pass', $password, PDO::PARAM_STR);
$stmt->execute();
$result = $stmt->fetch(PDO::FETCH_OBJ);
if ($result) {
AmfphpAuthentication::addRole($result->user_role);
unset($result->password);
return $result;
} else {
return false;
}
}
示例2: updateUser
/**
* function to update an existing AMFPHP authentication user
* @param string $firstName
* @param string $lastName
* @param string $userName
* @param string $password
* @param int $userRoleId
* @param int $id
* @return type
* @throws Exception
*/
public function updateUser($firstName, $lastName, $userName, $password, $userRoleId, $id)
{
try {
$pdo = MySQLUtil::getConnection();
// hash the password
$password = DBUtils::hashPassword($password);
$tsql = "UPDATE users SET first_name = :firstName, last_name = :lastName, username = :username, password = :password, user_role_id = :userRoleId WHERE id = :userId";
$stmt = $pdo->prepare($tsql);
$stmt->bindParam(':firstName', $firstName, PDO::PARAM_STR);
$stmt->bindParam(':lastName', $lastName, PDO::PARAM_STR);
$stmt->bindParam(':username', $userName, PDO::PARAM_STR);
$stmt->bindParam(':password', $password, PDO::PARAM_STR);
$stmt->bindParam(':userRoleId', $userRoleId, PDO::PARAM_INT);
$stmt->bindParam(':userId', $id, PDO::PARAM_INT);
return $stmt->execute();
} catch (PDOException $e) {
$error = date("Y-m-d g:i:s a T") . "\tUserService::updateUser\tError: (" . $e->getCode . ") " . $e->getMessage;
throw new Exception($error);
}
}