本文整理汇总了PHP中AuthComponent::password方法的典型用法代码示例。如果您正苦于以下问题:PHP AuthComponent::password方法的具体用法?PHP AuthComponent::password怎么用?PHP AuthComponent::password使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AuthComponent
的用法示例。
在下文中一共展示了AuthComponent::password方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: beforeSave
public function beforeSave($options = array())
{
/* password hashing */
if (isset($this->data[$this->alias]['password'])) {
$this->data[$this->alias]['password'] = AuthComponent::password($this->data[$this->alias]['password']);
}
}
示例2: install
public function install()
{
//TODO check if tables are present in db. If not, trigger schema create --plugin Backend
// setup default backend user groups
$groups = array('superuser' => array('name' => 'Superuser', 'root' => true), 'admin' => array('name' => 'Administrator', 'root' => false));
$BackendUserGroup = ClassRegistry::init('Backend.BackendUserGroup');
foreach ($groups as &$group) {
$BackendUserGroup->create();
if (!$BackendUserGroup->save(array('BackendUserGroup' => $group))) {
$this->out('<warning>Failed to create Backend User Group ' . $group['name'] . '</warning>');
} else {
$this->out('<success>Created Backend User Group ' . $group['name'] . '</success>');
}
}
// setup superuser
$superGroup = $BackendUserGroup->find('first', array('conditions' => array('BackendUserGroup.root' => true)));
if (!$superGroup) {
$this->error('No root BackendUserGroup found');
}
$email = $this->in('Superuser email:', '', 'flohax@yahoo.de');
$superuser = array('backend_user_group_id' => $superGroup['BackendUserGroup']['id'], 'username' => 'superuser', 'password' => AuthComponent::password('superPass'), 'first_name' => 'John', 'last_name' => 'Doe', 'mail' => $email, 'published' => true);
$BackendUser = ClassRegistry::init('Backend.BackendUser');
if (!$BackendUser->save(array('BackendUser' => $superuser), true)) {
$this->out('<warning>Failed to create Backend Superuser</warning>');
} else {
$this->out('<success>Superuser created (Password: superPass)</success>');
}
}
示例3: beforeSave
public function beforeSave($options = array())
{
//when password field
if (isset($this->data[$this->alias]['password']) && isset($this->data[$this->alias]['password2'])) {
if (empty($this->data[$this->alias]['password']) && empty($this->data[$this->alias]['password2'])) {
unset($this->data[$this->alias]['password']);
unset($this->data[$this->alias]['password2']);
} elseif (!empty($this->data[$this->alias]['password'])) {
if ($this->data[$this->alias]['password'] != $this->data[$this->alias]['password2']) {
$this->invalidate('password', __d('backend', "The passwords do not match"));
$this->invalidate('password2', __d('backend', "The passwords do not match"));
$this->data[$this->alias]['password2'] = null;
return false;
}
}
} elseif (isset($this->data[$this->alias]['password'])) {
$this->invalidate('password', __d('backend', 'Password verification not submitted'));
$this->invalidate('password2', __d('backend', 'Password verification not submitted'));
return false;
}
if (isset($this->data[$this->alias]['password']) && !empty($this->data[$this->alias]['password'])) {
$this->data[$this->alias]['password'] = AuthComponent::password($this->data[$this->alias]['password']);
}
return true;
}
示例4: index
public function index()
{
if ($this->Auth->user('id')) {
$user = $this->User->findById($this->Auth->user());
$this->set('user', $user);
if ($this->request->is('post')) {
$req = $this->request->data;
if ($user['User']['password'] == AuthComponent::password($req['User']['old_password'])) {
if ($req['User']['password'] == $req['User']['password_verify']) {
$user['User']['password'] = $req['User']['password'];
if ($this->User->save($user)) {
$this->Session->setFlash('New Password Saved!');
} else {
$this->Session->setFlash('The new passwords didn\'t match.');
}
} else {
$this->Session->setFlash('The new passwords didn\'t match.');
}
} else {
$this->Session->setFlash('The old password you entered was incorrect');
}
}
} else {
$this->redirect('/login');
}
}
示例5: save_user
function save_user($data = null)
{
$user_id = "";
if (isset($data['User']['parent_id']) && $data['User']['parent_id'] == "") {
$data['User']['parent_id'] = 0;
}
if (isset($data['User']['is_dealer']) && $data['User']['is_dealer'] == "") {
$data['User']['is_dealer'] = 0;
}
if (isset($data['User']['role_id']) && $data['User']['role_id'] == 2) {
//|| ($data['User']['role_id'] == 3)
} else {
unset($data['User']['selling_price_limit']);
}
if (!empty($data['User']['powd'])) {
$data['User']['powd'] = AuthComponent::password(AuthComponent::password($data['User']['powd']));
}
if (isset($data['User']['id']) && trim($data['User']['powd'] == "")) {
unset($data['User']['powd']);
}
if ($this->saveAll($data)) {
if (isset($data['User']['id']) && !empty($data['User']['id'])) {
$user_id = $data['User']['id'];
} else {
$user_id = $this->getLastInsertId();
}
}
return $user_id;
}
示例6: beforeSave
public function beforeSave($options = array())
{
parent::beforeSave($options);
if (isset($this->data['User']['password'])) {
$this->data['User']['password'] = AuthComponent::password($this->data['User']['password']);
}
}
示例7: beforeSave
public function beforeSave($options = array())
{
if (!empty($this->data['User']['image'])) {
if ($this->data['User']['image']['size'] != 0) {
$fileData = $this->resizeImage(512, $this->data['User']['image']['tmp_name']);
if (!isset($fileData)) {
$fileData = fread(fopen($this->data['User']['image']['tmp_name'], 'r'), $this->data['User']['image']['size']);
}
// debug($fileData);
// throw new Exception;
$this->data['User']['image_type'] = $this->data['User']['image']['type'];
$this->data['User']['image'] = $fileData;
} else {
$this->data['User']['image'] = null;
$this->data['User']['image_extension'] = null;
}
}
//App::import('Component','Auth');
//$AuthComponent = new AuthComponent(new ComponentCollection);
//AuthComponent->password($this->data['User']['password'])
if (isset($this->data[$this->alias]['password']) && strlen(trim($this->data[$this->alias]['password'])) != 0) {
$this->data[$this->alias]['password'] = AuthComponent::password($this->data['User']['password']);
} else {
unset($this->data['User']['password']);
}
return true;
}
示例8: beforeSave
/**
* Hash passwords
* @see Model::beforeSave()
*/
public function beforeSave($options = array())
{
if (!empty($this->data[$this->alias]['password'])) {
$this->data[$this->alias]['password'] = AuthComponent::password($this->data[$this->alias]['password']);
}
return TRUE;
}
示例9: change_password
public function change_password($id = null)
{
$this->set('subid', 'change_pass');
$this->set('titulo', 'Usuários');
$this->set('subtitulo', '');
$this->loadModel('Group');
$erros = array();
if ($this->request->is('post')) {
$currentpass = $this->Auth->password($this->request->data['User']['current_password']);
$exists = $this->User->findByUsernameAndPassword($this->Auth->user('username'), $currentpass);
if (!$exists) {
$this->Session->setFlash('Senha Errada', 'flash_custom', array('type' => 'error'));
return;
}
$pass = $this->request->data['User']['password'];
if ($pass != $this->request->data['User']['password_confirm']) {
$this->Session->setFlash('A senha e a confirmação precisam ser iguais', 'flash_custom', array('type' => 'error'));
return;
}
$novocurso = array('password' => $this->Auth->password($pass));
$this->User->id = $this->Auth->user('id');
if ($this->User->save($novocurso, false) && !count($erros)) {
$this->Session->setFlash('Senha trocada com sucesso', 'flash_custom', array('type' => 'success'));
$this->redirect(array('controller' => 'Users', 'action' => 'index'));
} else {
$erros = array_merge($erros, $this->User->validationErrors);
$this->set('user', $novocurso);
}
}
if (count($erros)) {
$this->Session->setFlash('O formulário contém erros', 'flash_custom', array('type' => 'error'));
}
$this->set('erros', $erros);
}
示例10: beforeSave
public function beforeSave($options = array())
{
if (isset($this->data['CloggyUser']['user_password']) && !empty($this->data['CloggyUser']['user_password'])) {
$this->data['CloggyUser']['user_password'] = AuthComponent::password($this->data['CloggyUser']['user_password']);
}
return true;
}
示例11: recover
public function recover()
{
$this->autoRender = false;
$email = $this->param('email');
$this->loadModel('User');
$usr = $this->User->findByEmail($email);
if ($usr) {
$this->User->create();
$this->User->id = $usr['User']['id'];
$mail = $this->PHPMailer->getPHPMailer();
$nova = $this->randomPassword();
$this->User->saveField('password', AuthComponent::password($nova));
$mail->AddAddress($email);
$mail->SetFrom('website@marialembrancinha.com.br', 'Website');
$mail->Subject = utf8_decode("Recuperação de Senha");
$mail->MsgHTML("Sua nova senha: {$nova}");
$sent = $mail->Send();
if (!$sent) {
echo json_encode(new Message(0, 'E-mail nao pode ser enviado'));
return;
}
echo json_encode(new Message(1, 'Nova senha enviada para seu email'));
return;
}
echo json_encode(new Message(0, 'Erro ao recuperar sua senha'));
return;
}
示例12: beforeSave
public function beforeSave($options = array())
{
if (isset($this->data[$this->alias]['password'])) {
$this->data[$this->alias]['password'] = AuthComponent::password($this->data[$this->alias]['password']);
}
return true;
}
示例13: change_password
public function change_password()
{
if ($this->request->is('post')) {
$old_pass = AuthComponent::password($this->data['Admin']['old_password']);
$check_exist = $this->Admin->findByPassword($old_pass);
if ($check_exist) {
$update_new_pass = array();
$update_new_pass['Admin']['id'] = $this->activeUser['User']['id'];
$update_new_pass['Admin']['password'] = $this->data['Admin']['new_password'];
if ($this->Admin->save($update_new_pass)) {
// Display success message and redirect
$this->Session->setFlash('Password changed successfully.', 'default', array('class' => 'alert alert-success'), 'success');
$this->redirect(array('controller' => 'home', 'action' => 'index'));
} else {
// Display failure message and redirect
$this->Session->setFlash('Sorry, an error occurred.', 'default', array('class' => 'alert alert-danger'), 'error');
$this->redirect(array('controller' => 'admins', 'action' => 'change_password'));
}
} else {
// Display failure message and redirect
$this->Session->setFlash('Invalid current password.', 'default', array('class' => 'alert alert-danger'), 'error');
$this->redirect(array('controller' => 'admins', 'action' => 'change_password'));
}
}
// Set the view variables to controller variable values and layout for the view
$this->set('page_title', 'Change Password');
$this->layout = "base_layout";
}
示例14: beforeSave
/**
* beforeSave callback
* Check if user name is unique and allowed in aro
* Encrypt password
*
* @param array model options
* @access public
* @return boolean
*/
public function beforeSave($options = array())
{
App::uses('Aro', 'Model');
$this->Aro = new Aro();
// alias = user name , must be unique
$this->Aro->validate = array('alias' => array('rule' => 'isUnique', 'message' => __('This name is restricted by system.')));
$aro = $this->Aro->findByForeignKey($this->id);
if ($aro) {
$aro['Aro']['alias'] = $this->data['User']['name'];
$aro = $aro['Aro'];
$this->Aro->set($aro);
}
if ($aro && !$this->Aro->validates($aro)) {
$errors = $this->Aro->validationErrors;
$this->data = null;
return false;
}
// crypt and truncate password
if (isset($this->data[$this->alias]['password'])) {
$this->data[$this->alias]['password'] = AuthComponent::password(substr($this->data[$this->alias]['password'], 0, 8));
}
// truncate username
if (isset($this->data[$this->alias]['username'])) {
$this->data[$this->alias]['username'] = substr($this->data[$this->alias]['username'], 0, 8);
}
return true;
}
示例15: beforeSave
/**
* Cada vez que um um usuario for salvo, faz hash da senha dele, que sera
* gravada no banco
* @return boolean
*/
public function beforeSave()
{
if (isset($this->data[$this->alias]['senha'])) {
$this->data[$this->alias]['senha'] = AuthComponent::password($this->data[$this->alias]['senha']);
}
return true;
}