public function login(Request $request) { // Post data $post_data = ['email' => $request->input('email'), 'password' => $request->input('password')]; // Remember token $remember = $request->input('remember'); // Attempt to log in if (Auth::attempt($post_data, $remember)) { // If login is successful return true and user data return response(['success' => true, 'user' => Auth::user()], 200); } else { // Login attempt failed so check if the user exists $user = User::whereEmail($post_data['email'])->first(); if (count($user) === 0) { // If user does not exist then return false return response(['success' => false, 'user' => false, 'message' => 'User does not exist'], 400); } else { // If user does exist then check the password. If the password doesn't match then return false if (!Hash::check($post_data['password'], $user->password)) { return response(['success' => false, 'user' => true, 'password' => false, 'message' => 'Wrong password'], 400); } else { // It's all jacked up return response(['success' => false, 'message' => 'Server error'], 500); } } } }
public function login() { $aRequest = \Input::all(); $sUsername = $aRequest['username']; $sPassword = $aRequest['password']; //Check if there's a user with this name, if yes, get all needed information for them $aResult = DB::table('users')->where(array('username' => $sUsername))->get(array('*')); if (!empty($aResult)) { //If execution reached here then the user is normal user. $sUserType = 'user'; } if (empty($aResult)) { //Check if the user is a restaurant $aResult = DB::table('restaurants')->where(array('username' => $sUsername))->get(array('*')); $sUserType = 'restaurant'; \Session::put('loggedin', 'true'); \Session::put('username', $sUsername); \Session::put('id_user', $aResult[0]->id_restaurant); \Session::put('user_type', $sUserType); //PUT THE SESSION FOR THE RESTAURANT return redirect()->intended('/'); } if (empty($aResult)) { return redirect('login')->withErrors('User not found!'); } if (Hash::check($sPassword, $aResult[0]->password)) { \Session::put('loggedin', 'true'); \Session::put('username', $sUsername); \Session::put('id_user', $aResult[0]->id_user); \Session::put('user_type', $sUserType); return redirect()->intended('/'); } else { return redirect('login')->withErrors(['Password is wrong!!', 'Error']); } }
public function loginAction(Request $request) { //$data=[]; //empty data can't output middware error if (!$request->session()->has('loginError')) { $data = []; } else { $data['loginError'] = $request->session()->get('loginError'); } if ($request->method() == 'POST') { $input = $request->input(); $validator = Validator::make($input, ['username' => 'required|max:255', 'password' => 'required|max:255']); if ($validator->fails()) { return Redirect::route('login')->withErrors($validator)->withInput($input); } //other ways to find user? $userObject = new User(); $row = $userObject->where('username', $input['username'])->first(); $data['username'] = $input['username']; if (isset($row)) { $passHash = $row->password; if (Hash::check($input['password'], $passHash)) { $request->session()->put(['username' => $row->username, 'id' => $row->id]); return Redirect::route('home'); } $data['loginError'] = "Invalid Password"; } else { $data['loginError'] = "No such user!"; unset($data['username']); } } return View::make('login', $data); }
public function validateCurrentPassword($attribute, $value, $parameters) { if (Hash::check($value, Auth::user()->password)) { return true; } return false; }
public function login(Request $request) { if (!empty($request->input('email'))) { $email = $request->input('email'); $password = $request->input('password'); $user_node = $this->users->getUser($email); // Create the Person model $user = new Person(); $user->setNode($user_node); if (!empty($user_node)) { // Check password and verification if (!$user->verified) { $message_bag = new MessageBag(); return redirect()->back()->with('errors', $message_bag->add('email', 'Dit emailadres is nog niet geverifieerd.')); } elseif (Hash::check($password, $user->password)) { Auth::login($user); // Register the event to Piwik $this->registerPiwikEvent($user->email, 'Login'); return redirect($this->redirectTo); } else { $message_bag = new MessageBag(); return redirect()->back()->with('errors', $message_bag->add('password', 'Het wachtwoord is incorrect.')); } } else { $message_bag = new MessageBag(); return redirect()->back()->with('errors', $message_bag->add('email', 'Het emailadres werd niet gevonden.')); } } else { $message_bag = new MessageBag(); return redirect()->back()->with('errors', $message_bag->add('email', 'Het emailadres werd niet gevonden.')); } }
public function checkPassword($password) { if (Hash::check($password, $this->attributes['password'])) { return true; } return false; }
/** * Determine if the user is authorized to make this request. * * @return bool */ public function authorize() { $name_or_email = $this->input('name_or_email'); $password = $this->input('password'); $db_field = filter_var($name_or_email, FILTER_VALIDATE_EMAIL) ? 'email' : 'name'; $user = User::where($db_field, '=', $name_or_email)->first(); if ($db_field == 'name') { $name_change = NameChange::where('old_name', '=', $name_or_email)->first(); if ($name_change != null) { // Username used to be the input, but it was changed Flash::error('It seems like you\'re trying to log in with a username that has changed. Please use your new username.'); return false; } } if ($user == null || !$user) { Flash::error('User not found'); return false; } if (!Hash::check($password, $user->password)) { Flash::error('Invalid password'); return false; } if (Auth::attempt([$db_field => $name_or_email, 'password' => $password], $this->has('remember'))) { return true; } else { Flash::error('You could not be logged in due to an unknown error.'); return false; } return false; }
/** * Bootstrap any application services. * * @return void */ public function boot() { Validator::extend('hashed', function ($attribute, $value, $parameters) { // If we're already logged in if (Auth::check()) { $user = Auth::user(); } else { // Otherwise, try to get the username from form input $user = User::where('name', Input::get('name'))->get(); if (!$user->count()) { return false; } $user = $user[0]; } if (Hash::check($value, $user->password)) { return true; } return false; }); Validator::extend('time', function ($attribute, $value, $parameters) { $value = trim($value); // Check against 12 hour time (with AM/PM) or 24 hour time $twelve = date_parse_from_format('h:i a', $value); $twentyfour = date_parse_from_format('H:i', $value); if ($twelve['error_count'] === 0 || $twentyfour['error_count'] === 0) { return true; } return false; }); }
public function authenticate(Request $request) { $credenciales = $request->only('email', 'password'); try { if (!($token = JWTAuth::attempt($credenciales))) { return response()->json(['error' => 'Credenciales Invalidas'], 401); } $usuario = DB::table('usuarios')->where('email', '=', $request->get('email'))->first(); if ($usuario) { if ($usuario->estado == "activo") { if (Hash::check($credenciales['password'], $usuario->password)) { $sesion = new SesionController(); if ($sesion->registrar_sesion($usuario->id_usuario)) { return response()->json(['usuario' => $usuario, compact('token')], 201); } else { return response()->json(['error' => true, 'mensaje' => 'Error, intente iniciar sesion nuevamente']); } } else { return response()->json(['error' => true, 'mensaje' => 'Error, Password Incorrecta']); } } else { return response()->json(['error' => true, 'mensaje' => 'Error, el usuario no existe']); } } else { return response()->json(['error' => true, 'mensaje' => 'Verifique email y password']); } } catch (JWTException $e) { return response()->json(['error' => 'Falta Token'], 500); } }
public function logar(Request $request) { $validacao = Validator::make($request->all(), ['email' => 'required|email', 'password' => 'required|string']); if ($validacao->fails()) { return redirect('admin/login')->withErrors($validacao)->withInput(); } else { $usuario = User::where('email', '=', $request->email)->first(); if ($usuario) { $senhaIgual = Hash::check($request->password, $usuario->password); if ($senhaIgual) { if (!Auth::check()) { Auth::login($usuario); $usuario->ultimo_acesso = date('Y-m-d H:i:s'); $usuario->save(); return Redirect::to('/admin/dashboard'); } elseif (Auth::check()) { $usuario->ultimo_acesso = date('Y-m-d H:i:s'); $usuario->save(); return Redirect::to('/admin/dashboard'); } else { session()->flash('flash_message', 'Usuário ou senha inválidos'); return Redirect::to('/admin/login')->withInput(); } } else { session()->flash('flash_message', 'Usuário ou senha inválidos'); return Redirect::to('/admin/login')->withInput(); } } else { session()->flash('flash_message', 'Usuário ou senha inválidos'); return Redirect::to('/admin/login')->withInput(); } } }
public function login(Request $request) { $input = $request->json()->all(); $validator = Validator::make($input, ['email' => 'required|email', 'password' => 'required', 'deviceId' => 'required']); if ($validator->fails()) { $error = $validator->errors()->all(); return response()->json(['errorMessage' => [$error]], 404); } $deviceId = $input['deviceId']; $result = DB::table('users')->where('email', $input['email'])->first(); if ($result && Hash::check($input['password'], $result->password)) { $res = DB::table('tokens')->where('deviceId', $deviceId)->first(); if ($res) { $token = Token::find($res->id); $token->token = bin2hex(openssl_random_pseudo_bytes(64)); $token->save(); } else { DB::table('tokens')->insert(['token' => bin2hex(openssl_random_pseudo_bytes(64)), 'userId' => $result->id, 'deviceId' => $deviceId]); } $token = DB::table('tokens')->select('token')->where('userId', $result->id)->where('deviceId', $deviceId)->first(); if ($token) { return response()->json($token); } else { return response()->json(['errorMessage' => 'login failed'], 404); } } else { return response()->json(['errorMessage' => 'this user not found'], 404); } }
public function test_can_create_user() { $user = $this->app->make(UserRepositoryInterface::class)->create(['name' => 'Test', 'email' => '*****@*****.**', 'password' => '123456']); $this->assertEquals('Test', $user->name); $this->assertEquals('*****@*****.**', $user->email); $this->assertTrue(Hash::check('123456', $user->password)); }
/** * Bootstrap any application services. * * @return void */ public function boot() { Validator::extend('check_auth_user_password', function ($attribute, $value, $parameters, $validator) { return Hash::check($value, Auth::user()->password); }); // Make sure client email is not used by another client of current user Validator::extend('email_not_used_by_another_user_client', function ($attribute, $value, $parameters, $validator) { if (Client::where('user_id', Auth::user()->id)->where('email', $value)->count()) { return false; } return true; }); // Make sure client phone number is not user by another client of current user Validator::extend('phone_number_not_used_by_another_user_client', function ($attribute, $value, $parameters, $validator) { if (Client::where('user_id', Auth::user()->id)->where('phone_number', $value)->count()) { return false; } return true; }); Validator::extend('not_exists', function ($attribute, $value, $parameters, $validator) { return !DB::table($parameters[0])->where($parameters[1], $value)->count(); }); Validator::extend('is_not_in_auth_user_products', function ($attribute, $value, $parameters, $validator) { return !DB::table('products')->where('user_id', \Auth::user()->id)->where('code', $value)->count(); }); }
/** * POST /api/login */ public function login() { // Get all data send in post $loginFormData = Request::all(); // Create rules for the validator $validator = Validator::make($loginFormData, ['user_email' => 'required|email', 'user_password' => 'required']); // If validator fails return a 404 response if ($validator->fails()) { return Response::json(['status_code' => 404, 'errors' => $validator->errors()->all()], 404); } $user = User::where('email', '=', strtolower($loginFormData['user_email']))->first(); if (!$user) { return Response::json(['status_code' => 404, 'errors' => ['Votre compte est introuvable dans notre base de donnée.']], 404); } else { if ($user->activated == 0) { return Response::json(['status_code' => 404, 'errors' => ["Merci d'activer votre compte."]], 404); } else { if (!Hash::check($loginFormData['user_password'], $user->password)) { return Response::json(['status_code' => 404, 'errors' => ["Votre mot de passe est incorrect."]], 404); } } } $room = Room::find($user->room_id); $partner = User::find($user->is_partner ? $room->user_id : $room->partner_id); if ($partner->activated == 0) { return Response::json(['status_code' => 404, 'errors' => ["Le compte de votre partenaire n'a pas été activé."]], 404); } // Success return Response::json(['status_code' => 200, 'success' => "Login success", 'data' => ['me' => $user, 'partner' => $partner, 'room' => $room]]); }
public function test_can_create_user() { $user = $this->createUser(); $this->assertEquals('Test', $user->name); $this->assertEquals('*****@*****.**', $user->email); $this->assertTrue(Hash::check('123456', $user->password)); }
public function checkPassword($password, $hash) { if (Hash::check($password, $hash)) { return "Yay :D"; } else { return "Naay :("; } }
/** * Handle the reauthentication request to the application. * * @param \Illuminate\Http\Request $request * * @return \Illuminate\Http\Response */ public function postReauthenticate(Request $request) { $this->validateLogin($request); if (Hash::check($request->{$this->authEntity()}, Auth::guard($this->getGuard())->user()->getAuthPassword())) { return $this->handleUserVerifiedAuthentication($request); } return $this->sendFailedLoginResponse($request); }
/** * Private function to check the Password based on the User object and Password * @param $user * @param $password * @return bool */ public function checkPassword($user, $password) { $status = false; if (Hash::check($password, $user->password)) { $status = true; } return $status; }
public function test_can_register_success() { $this->addValidator(); $this->post('/auth/register', ['username' => 'learner', 'email' => '*****@*****.**', 'password' => '121212', 'password_confirmation' => '121212']); $user = User::find(1); $this->assertEquals($user->email, '*****@*****.**'); $this->assertTrue(Hash::check('121212', $user->password)); }
/** * Change the user's password. * * @param UserRepository $repository * @param PasswordChangeRequest $request * @return \Illuminate\Http\RedirectResponse */ public function changePassword(UserRepository $repository, PasswordChangeRequest $request) { if (Hash::check($request->get('current_password'), Auth::user()->password)) { $repository->changePassword(Auth::user(), $request->get('password')); return redirect()->back()->with(['notice' => Lang::get('auth.password_changed')]); } return redirect()->back()->withErrors(['password_no_match' => Lang::get('auth.password_no_match')]); }
/** * Verify user's credentials. * * @param string $email * @param string $password * @return int|boolean * @see https://github.com/lucadegasperi/oauth2-server-laravel/blob/master/docs/authorization-server/password.md */ public function verify($email, $password) { $user = User::where('email', $email)->first(); if ($user && Hash::check($password, $user->password)) { return $user->id; } return false; }
public static function isAccountValid($email, $password) { $user = User::where('email', $email)->first(); if ($user != null) { return Hash::check($password, $user->password); } return false; }
/** * Update the user's password. * * @param Request $request * @return Response */ public function update(Request $request) { $this->validate($request, ['current_password' => 'required', 'password' => 'required|confirmed|min:6']); if (!Hash::check($request->current_password, $request->user()->password)) { return response()->json(['current_password' => ['The given password does not match our records.']], 422); } $request->user()->forceFill(['password' => bcrypt($request->password)])->save(); }
/** * Validate the user current/old password. * * @param string $attribute * @param string $value * @param array $parameters * @param \Illuminate\Validation\Validator $validator * * @return bool */ public function validateUserPassword($attribute, $value, $parameters, $validator) { unset($attribute, $parameters, $validator); if (auth()->guest()) { return false; } return Hash::check($value, auth()->user()->password); }
protected function checkOldPassword() { if (!empty($this->command->password)) { if (!Hash::check($this->command->old_password, $this->foundUser->password)) { throw new InvalidOldPasswordException("Password are not the same"); } } }
/** * Authenticate a user by username and password. * * @param string $username The username * @param string $password Plain text password * @return bool|user The user if the password matches the user's stored password, false otherwise. */ public function authenticate($username, $password) { $user = User::where('username', $username)->first(); if (!Hash::check($password, $user->password)) { return false; } return $user; }
/** * Restituisce l'utente il cui indirizzo email è $emailAddress e la password è $password. * * @param $emailAddress * @param $password * @return \Illuminate\Database\Eloquent\Model|UserRepository|null|static * @throws NotFoundException */ public function findByEmailAndPassword($emailAddress, $password) { $user = $this->findBy(['email' => $emailAddress, 'is_confirmed' => true]); if (!$user || !Hash::check($password, $user->password)) { throw new NotFoundException(); } return $user; }
/** * Check old password is correct or not * @param integer $userId * @param string $oldPassword * @return boolean $flag */ public function checkOldPassword($userId, $oldPassword) { $data = UserModel::find($userId); $flag = FALSE; if (Hash::check($oldPassword, $data->password)) { $flag = TRUE; } return $flag; }
/** * Attempt to Reauthenticate the user. * * @param string $password * * @return bool */ public function attempt($password) { if (!Hash::check($password, Auth::user()->getAuthPassword())) { return false; } $this->request->session()->set($this->key . '.life', Carbon::now()->timestamp); $this->request->session()->set($this->key . '.authenticated', true); return true; }
/** * Update the user's password. * * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\Response */ public function updatePassword(Request $request) { $this->validate($request, ['old_password' => 'required', 'password' => 'required|confirmed|min:6']); if (!Hash::check($request->old_password, Auth::user()->password)) { return response()->json(['The old password you provided is incorrect.'], 422); } Auth::user()->password = Hash::make($request->password); Auth::user()->save(); }