authenticate() public static méthode

Authenticate a user given the username/password credentials
public static authenticate ( array $credentials, boolean $remember = false ) : boolean
$credentials array Credential information (must include "username" and "password")
$remember boolean Flag to activate the "remember me" functionality
Résultat boolean Pass/fail of authentication
Exemple #1
0
 public function login($username, $pass)
 {
     $credentials = array('username' => $username, 'password' => $pass);
     if (Gatekeeper::authenticate($credentials) == true) {
         $_SESSION['username'] = $username;
         $_SESSION['pass'] = $pass;
         return true;
     }
     return false;
 }
Exemple #2
0
 public function processLoginAction()
 {
     $success = false;
     try {
         $success = Gatekeeper::authenticate(['username' => $_POST['email'], 'password' => $_POST['password']]);
     } catch (\Exception $e) {
         $this->flasher->error($this->site['debug'] ? $e->getMessage() : 'Something went wrong');
         $this->redirect('/auth');
     }
     if ($success) {
         $_SESSION['user'] = $_POST['email'];
         $this->redirect('/');
     } else {
         $this->flasher->error('Invalid credentials!');
         $this->redirect('/auth');
     }
 }
Exemple #3
0
 /**
  * @auth-groups users
  */
 public function saveAction()
 {
     if (!empty($_POST['password_new'])) {
         try {
             v::length(6)->check($_POST['password_new']);
         } catch (ValidationException $e) {
             $this->flasher->error('Please make sure new password is longer than 6 characters!');
         }
         if ($_POST['password_new'] !== $_POST['password_new_confirm']) {
             $this->flasher->error('New password fields were not identical!');
         }
         if (!Gatekeeper::authenticate(['username' => $this->user->username, 'password' => $_POST['password_old']])) {
             $this->flasher->error('Invalid password. Changes ignored.');
         } else {
             $this->user->password = $_POST['password_new'];
             $this->user->save();
             $this->flasher->success('Password updated!');
         }
     }
     if ($_POST['firstname'] != '-') {
         try {
             v::alnum(' ')->check($_POST['firstname']);
             $this->user->firstName = $_POST['firstname'];
             $this->user->save();
             $this->flasher->success('First name changed.');
         } catch (ValidationException $e) {
             $this->flasher->error('Name contains invalid characters. ' . $e->getMainMessage());
         }
     }
     if ($_POST['lastname'] != '-') {
         try {
             v::alnum(' ')->check($_POST['lastname']);
             $this->user->lastName = $_POST['lastname'];
             $this->user->save();
             $this->flasher->success('Last name changed.');
         } catch (ValidationException $e) {
             $this->flasher->error('Last name contains invalid characters. ' . $e->getMainMessage());
         }
     }
     $this->redirect('/account');
 }
 /**
  * Validate a user against the given credentials.
  *
  * @param  \Illuminate\Contracts\Auth\Authenticatable $user
  * @param  array  $credentials
  * @return bool
  */
 public function validateCredentials(Authenticatable $user, array $credentials)
 {
     $username = $user->getAuthIdentifier();
     $credentials = ['username' => $username, 'password' => $credentials['password']];
     return Gatekeeper::authenticate($credentials);
 }
Exemple #5
0
 /**
  * Validate a user against the given credentials.
  *
  * @param  \Illuminate\Auth\UserInterface  $user
  * @param  array $credentials
  * @return bool
  */
 public function validateCredentials(\Illuminate\Auth\UserInterface $user, array $credentials)
 {
     return Gatekeeper::authenticate($credentials);
 }