Example #1
0
 /**
  * Authenticate user by username and password
  *
  * @param string|array $data Username or array of username and password
  * @param string $password Password
  *
  * @return Boardy\Models\User
  */
 public static function attempt($data, $password = null)
 {
     EventDispatcher::dispatch('auth.attempt', new Event(func_get_args()));
     if (is_array($data)) {
         $password = $data['password'];
         $data = $data['username'];
     }
     if ($user = User::where('username', $data)->orWhere('email', $data)->first()) {
         if (!Hash::check($password, $user->password)) {
             EventDispatcher::dispatch('auth.fail', null);
             return;
         }
         if (Hash::needsRehash($user->password)) {
             $user->password = $password;
             $user->save();
             EventDispatcher::dispatch('auth.rehash', $user);
         }
         return $user;
     }
 }
Example #2
0
 /**
  * Allows for automatic password hashing
  *
  * @param string $password User's password
  */
 public function setPasswordAttribute($password)
 {
     $this->attributes['password'] = Hash::make($password);
 }