本文整理汇总了PHP中CPasswordHelper::hashPassword方法的典型用法代码示例。如果您正苦于以下问题:PHP CPasswordHelper::hashPassword方法的具体用法?PHP CPasswordHelper::hashPassword怎么用?PHP CPasswordHelper::hashPassword使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CPasswordHelper
的用法示例。
在下文中一共展示了CPasswordHelper::hashPassword方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: createAdmin
public function createAdmin()
{
$attributes = array('username' => 'admin', 'email' => 'test@mail.kom', 'password' => CPasswordHelper::hashPassword('iddqd3311'), 'email_verified' => 1);
$user = new Users();
$user->attributes = $attributes;
$user->save();
}
示例2: beforeSave
protected function beforeSave()
{
if (isset($this->senha)) {
$this->senha = CPasswordHelper::hashPassword($this->senha);
}
return parent::beforeSave();
}
示例3: actionRegister
public function actionRegister()
{
$username = $_POST['username'];
$password = $_POST['password'];
if (strlen($username) < 3) {
Helper::renderJSONErorr("Username must be at least 3 symbols: {$username} [" . strlen($username) . "]");
}
if (strlen($password) < 5) {
Helper::renderJSONErorr("Password must be at least 5 symbols");
}
// Check user
$user = User::model()->find('username=:username', array(':username' => $username));
if ($user) {
Helper::renderJSONErorr("Username occupated");
}
// Create new user
$model = new User();
$model->username = $username;
$model->password = CPasswordHelper::hashPassword($password);
if ($model->save()) {
Helper::renderJSON($model);
}
// Catch errors
$errors = [];
foreach ($model->errors as $attribute => $attr_errors) {
foreach ($attr_errors as $attr_error) {
$errors[] = "Attribute {$attribute}: {$attr_error}";
}
}
Helper::renderJSONErorr(implode("\n", $errors));
}
示例4: actionCreate
/**
* Creates a new model.
* If creation is successful, the browser will be redirected to the 'view' page.
*/
public function actionCreate()
{
$model = new Propietario();
// Uncomment the following line if AJAX validation is needed
// $this->performAjaxValidation($model);
if (isset($_POST['Propietario'])) {
$model->attributes = $_POST['Propietario'];
$usuario = new Usuario();
$model->rut = Tools::removeDots($model->rut);
$usuario->user = $model->rut;
$arr = explode("-", $model->rut);
$usuario->clave = CPasswordHelper::hashPassword($arr[0]);
$usuario->rol = "propietario";
$usuario->nombre = $_POST['Propietario']['nombre'];
$usuario->email = $_POST['Propietario']['email'];
$usuario->apellido = $_POST['Propietario']['apellido'];
$model->usuario_id = 1;
if ($model->validate()) {
if ($usuario->validate()) {
if ($usuario->save()) {
$model->usuario_id = $usuario->id;
if ($model->save()) {
$auth = Yii::app()->authManager;
Authassignment::model()->deleteAllByAttributes(array('userid' => $usuario->id));
$auth->revoke($usuario->rol, $model->usuario_id);
$auth->assign($usuario->rol, $model->usuario_id);
$this->redirect(array('view', 'id' => $model->id));
}
}
}
}
}
$this->render('create', array('model' => $model));
}
示例5: __set
public function __set($name, $value)
{
if ($name === 'password') {
$value = CPasswordHelper::hashPassword($value);
}
parent::__set($name, $value);
// TODO: Change the autogenerated stub
}
示例6: hashPassword
/**
*
* 某些系统不支持crypt加密。只能用md5加密了
*
*
* @param password 客户端传递过来的密码
*@param array $params
* @return string
*/
public function hashPassword($password, array $params = array())
{
if (!function_exists('crypt')) {
return CPasswordHelper::hashPassword($password);
} else {
return md5($password);
}
}
示例7: changePassword
public function changePassword()
{
$user = Yii::app()->controller->user;
$user->password = CPasswordHelper::hashPassword($this->newPassword);
if ($user->save()) {
return true;
} else {
return false;
}
}
示例8: hashPassword
/**
* Hashes a given password with the blowfish encryption algorithm.
*
* @param string $string The string to hash
* @param bool $validateHash If you want to validate the just generated hash. Will throw an exception if
* validation fails.
*
* @throws Exception
* @return string The hash.
*/
public function hashPassword($string, $validateHash = false)
{
$hash = \CPasswordHelper::hashPassword($string, $this->_blowFishHashCost);
if ($validateHash) {
if (!$this->checkPassword($string, $hash)) {
throw new Exception(Craft::t('Could not hash the given string.'));
}
}
return $hash;
}
示例9: beforeSave
/**
* Este método se llama cuando inserto o edito un registro.
*/
public function beforeSave()
{
if (parent::beforeSave()) {
if (!empty($this->newPassword) && $this->newPassword == $this->rePassword) {
$this->password = CPasswordHelper::hashPassword($this->newPassword);
}
return true;
}
return false;
}
示例10: save
/**
* Updates the users password.
* @param bool $runValidation
*/
public function save($runValidation = true)
{
if ($runValidation && !$this->validate()) {
return false;
}
/** @var AccountModule $account */
$account = Yii::app()->getModule('account');
$this->user->{$account->passwordField} = CPasswordHelper::hashPassword($this->new_password);
return $this->user->save(false);
}
示例11: beforeSave
public function beforeSave()
{
if ($this->isNewRecord) {
$this->created = new CDbExpression('NOW()');
}
$this->updated = new CDbExpression('NOW()');
if ($this->pass != '') {
$this->password = CPasswordHelper::hashPassword($this->pass);
}
return parent::beforeSave();
}
示例12: beforeSave
/**
* Password hashing
* @return bool
*/
protected function beforeSave()
{
if (parent::beforeSave()) {
if ($this->isNewRecord) {
$this->password = CPasswordHelper::hashPassword($this->password);
}
return true;
} else {
return false;
}
}
示例13: save
/**
* Updates the users password.
* @param bool $runValidation
*/
public function save($runValidation = true)
{
if ($runValidation && !$this->validate()) {
return false;
}
/** @var AccountModule $account */
$account = Yii::app()->getModule('account');
//to avoid indirect modification error message
$user = $this->user;
$user->{$account->passwordField} = CPasswordHelper::hashPassword($this->new_password);
return $user->save(false);
}
示例14: actionRegister
/**
* Creates a new model.
* If creation is successful, the browser will be redirected to the 'view' page.
*/
public function actionRegister()
{
$model = new User();
$this->performAjaxValidation($model);
if (isset($_POST['User'])) {
$model->attributes = $_POST['User'];
$model->password = CPasswordHelper::hashPassword($model->password);
if ($model->save()) {
$this->redirect(array('site/login'));
}
}
$this->render('register', array('model' => $model));
}
示例15: beforeSave
protected function beforeSave()
{
$this->username = trim(strtolower($this->username));
if ($this->password === '') {
$model2 = User::model()->findByPk($this->id);
$this->password = $model2->password;
$this->repeatPassword = $model2->password;
} elseif ($this->repeatPassword !== null) {
$this->unecryptedPassword = $this->password;
$this->password = CPasswordHelper::hashPassword($this->password);
$this->repeatPassword = CPasswordHelper::hashPassword($this->repeatPassword);
}
return true;
}