本文整理汇总了PHP中PassHash::hash方法的典型用法代码示例。如果您正苦于以下问题:PHP PassHash::hash方法的具体用法?PHP PassHash::hash怎么用?PHP PassHash::hash使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PassHash
的用法示例。
在下文中一共展示了PassHash::hash方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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);
}
}
示例2: 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;
}
示例3: 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)
{
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(name, email, password_hash, api_key, status) values(?, ?, ?, ?, 1)");
$stmt->bind_param("ssss", $name, $email, $password_hash, $api_key);
$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;
}
示例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, $comp)
{
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 il_user(name, email, password_hash, api_key, status,il_company_acc) values(?, ?, ?, ?, 1,?)");
$stmt->bind_param("sssss", $name, $email, $password_hash, $api_key, $comp);
$result = $stmt->execute();
$stmt->close();
// Check for successful insertion
if ($result) {
// User successfully inserted
return $result;
} else {
// Failed to create user
return 0;
}
} else {
// User with same email already existed in the db
return 2;
}
return $response;
}
示例5: registerAppUser
public function registerAppUser($params)
{
require_once 'PassHash.php';
$name = $params['name'];
$email = $params['email'];
$gcm_registration_id = $params['gcm_registration_id'];
$password = $params['password'];
$notify_app_status = $params['notify_app_status'];
$send_email_status = $params['send_email_status'];
$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 app_users (name, email, password_hash, api_key, app_notify_status, send_email_status, gcm_registration_id, edited_at) values(?, ?, ?, ?, ?, ?, ?, date('Y-m-d H:i:s'))");
$stmt->bind_param("ssssiis", $name, $email, $password_hash, $api_key, $notify_app_status, $send_email_status, $gcm_registration_id);
$result = $stmt->execute();
$stmt->close();
// Check for successful insertion
if ($result) {
return USER_CREATED_SUCCESSFULLY;
} else {
return USER_CREATE_FAILED;
}
} else {
return USER_ALREADY_EXISTED;
}
return $response;
}
示例6: 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, $gender)
{
require_once 'PassHash.php';
// 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`(`name`, `email`, `gender`, `password_hash`, `key`)
VALUES(:name, :email, :gender, :password_hash, :key)');
$stmt->execute(array('name' => $name, 'email' => $email, 'gender' => $gender, 'password_hash' => $password_hash, 'key' => $api_key));
// Check for successful insertion
if ($stmt->rowCount() > 0) {
// 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;
}
}
示例7: 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.'));
}
}
示例8: inserirUsuario
/**
* Inserir o usuário.
* @param type $usuario
*/
public function inserirUsuario($usuario, $tipoUsuario)
{
//caso usuário não seja criado o valor 0 será atribuído
$cdUsuario = ID_NAO_RETORNADO;
if (!$this->ehUsuarioExistente($usuario->login)) {
// Caso o usuário não exista será construída o Insert na tb_usuario.
$stmt = $this->conn->prepare("INSERT INTO tb_usuario(nm_login, " . "nm_senha, nm_apikey, nm_usuario, dt_nascimento," . " nm_sexo, cd_tipousuario, fl_ativo)" . " values(?, ?, ?, ?, ?, ?, " . $tipoUsuario . ", " . USUARIO_ATIVO . ")");
$nascimento = $data = implode("-", array_reverse(explode("/", $usuario->nascimento)));
$sexo = strtoupper($usuario->sexo);
$passwordHash = PassHash::hash($usuario->senha);
$apiKey = $this->gerarApiKey();
// Parâmetros: tipos das entradas, entradas.
$stmt->bind_param("ssssss", $usuario->login, $passwordHash, $apiKey, $usuario->nome, $nascimento, $sexo);
// Executar a consulta.
$result = $stmt->execute();
if ($result) {
$cdUsuario = $stmt->insert_id;
}
$stmt->close();
} else {
// Código para usuário já existente.
$cdUsuario = USUARIO_EXISTENTE;
}
return $cdUsuario;
}
示例9: createUser
public function createUser($firstName, $secondName, $userName, $eMail, $birthDate, $sex, $password)
{
require_once 'PassHash.php';
$response = array();
// First check if user already existed in db
if (!$this->isUserExists($userName)) {
// Generating password hash
$password_hash = PassHash::hash($password);
// Generating API key
$api_key = $this->generateApiKey();
// insert query
$stmt = $this->conn->prepare("INSERT INTO users(first_name, second_name, user_name, email, password_hash, api_key, birthdate, sex) \n \t\tvalues(?, ?, ?, ?, ?, ?, ?, ?)");
$stmt->bind_param("sssssssi", $firstName, $secondName, $userName, $eMail, $password_hash, $api_key, $birthDate, $sex);
$result = $stmt->execute();
$stmt->close();
// Check for successful insertion
if ($result) {
// User successfully inserted
$response['message'] = USER_CREATED_SUCCESSFULLY;
$response['api_key'] = $api_key;
} else {
// Failed to create user
$response['message'] = USER_CREATE_FAILED;
$response['api_key'] = 'no key';
}
} else {
// User with same username already existed in the db
$response['message'] = USER_ALREADY_EXIST;
$response['api_key'] = 'no key';
}
return $response;
}
示例10: createUser
/**
* Creating new user
* @param String $name User full name
* @param String $email User login email id
* @param String $password User login password
*/
public static function createUser($objUser)
{
if (User::where('email', $objUser['email'])->count() == 0) {
$user = User::create(array('username' => $objUser['username'], 'password' => PassHash::hash($objUser['password']), 'email' => $objUser['email'], 'type' => 2, 'startDate' => date('Y-m-d'), 'lastLogin' => date('Y-m-d'), 'apiKey' => $this->generateApiKey()));
$result = $user->save();
//= 1 success
if ($result) {
return USER_CREATED_SUCCESSFULLY;
} else {
return USER_CREATE_FAILED;
}
} else {
return USER_ALREADY_EXISTED;
}
}
示例11: 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'));
}
}
示例12: createUser
public function createUser($login, $password)
{
require_once 'PassHash.php';
$response = array();
if (!$this->isUserExists($login)) {
$password_hash = PassHash::hash($password);
$user_key = $this->generateApiKey();
$money = 0;
$stmt = $this->conn->prepare("INSERT INTO profile(login, password, money, user_key) values(?, ?, ?, ?)");
$stmt->bind_param("ssis", $login, $password_hash, $money, $user_key);
$result = $stmt->execute();
$stmt->close();
if ($result) {
return USER_CREATED_SUCCESSFULLY;
} else {
return USER_CREATE_FAILED;
}
} else {
return USER_ALREADY_EXISTED;
}
return $response;
}
示例13: createUser
public function createUser($user)
{
require_once 'PassHash.php';
$username = $user['username'];
$email = $user['email'];
$password = $user['password'];
// Generating password hash
$password_hash = PassHash::hash($password);
// insert query
$stmt = $this->conn->prepare("INSERT INTO users(username, email, password_hash) values(?, ?, ?)");
$stmt->bind_param("sss", $username, $email, $password_hash);
$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;
}
}
示例14: createUser
public function createUser($first_name, $last_name, $email, $user_name, $password)
{
//Get pass hash script
require_once 'PassHash.php';
//create an array for response return
$response = array();
//First check to see if user already exists (via email)
if (!$this->isUserExists($email)) {
//user account does not exist - create it
//Make a hashed password based on user inputted password
$password_hash = PassHash::hash($password);
//make user activation code
$active = md5(uniqid(rand(), true));
//prepare insert statement
$stmt = $this->conn->prepare("INSERT INTO user \n (first_name, last_name, email, user_name, password, date_expires, active)\n VALUES (:fname, :lname, :email, :uname, :password, SUBDATE(NOW(), INTERVAL 1 DAY), :active)");
$stmt->bindValue(':email', $email, PDO::PARAM_STR);
$stmt->bindValue(':password', $password_hash, PDO::PARAM_STR);
$stmt->bindValue(':fname', $first_name, PDO::PARAM_STR);
$stmt->bindValue(':lname', $last_name, PDO::PARAM_STR);
$stmt->bindValue(':uname', $user_name, PDO::PARAM_STR);
$stmt->bindValue(':active', $active, PDO::PARAM_STR);
$result = $stmt->execute();
//check for success|failure
if ($result) {
//success
$response['message'] = 'USER_SUCCESSFULLY_CREATED';
$response['active'] = $active;
} else {
//failure
$response['message'] = 'USER_CREATE_FAILED';
}
} else {
//user account already exists - return message
$response['message'] = 'USER_ALREADY_EXISTS';
}
//RETURN FINAL RESPONSE
return $response;
}
示例15: createUser
public function createUser($name, $email, $password)
{
require_once 'PassHash.php';
$response = [];
// check if user email alrready exists
if ($this->isUserExists($email)) {
return USER_ALREADY_EXISTED;
} else {
// generate password hash
$password_hash = PassHash::hash($password);
// generate api key
$api_key = $this->generateApiKey();
// insert query
$stmt = $this->conn->prepare("INSERT INTO user_regular \n (name, email, password_hash, api_key)\n VALUES (?, ?, ?, ?);");
$stmt->bind_param("ssss", $name, $email, $password_hash, $api_key);
$result = $stmt->execute();
if ($result) {
return USER_CREATED_SUCCESSFULLY;
} else {
return USER_CREATED_FAILED;
}
}
return $response;
}