当前位置: 首页>>代码示例>>PHP>>正文


PHP Hash::check方法代码示例

本文整理汇总了PHP中Illuminate\Support\Facades\Hash::check方法的典型用法代码示例。如果您正苦于以下问题:PHP Hash::check方法的具体用法?PHP Hash::check怎么用?PHP Hash::check使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Illuminate\Support\Facades\Hash的用法示例。


在下文中一共展示了Hash::check方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: loginAction

 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);
 }
开发者ID:Hsword,项目名称:Laravel_Toy_Blog,代码行数:32,代码来源:AuthController.php

示例2: login

 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']);
     }
 }
开发者ID:4Bara,项目名称:Fooder-Food-ordering-website-,代码行数:35,代码来源:loginController.php

示例3: validateCurrentPassword

 public function validateCurrentPassword($attribute, $value, $parameters)
 {
     if (Hash::check($value, Auth::user()->password)) {
         return true;
     }
     return false;
 }
开发者ID:amitavroy,项目名称:mywall,代码行数:7,代码来源:CurrentPasswordValidation.php

示例4: checkPassword

 public function checkPassword($password)
 {
     if (Hash::check($password, $this->attributes['password'])) {
         return true;
     }
     return false;
 }
开发者ID:lc0991,项目名称:Todo,代码行数:7,代码来源:User.php

示例5: authorize

 /**
  * 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;
 }
开发者ID:fetch404,项目名称:fetch404,代码行数:35,代码来源:LoginRequest.php

示例6: logar

 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();
         }
     }
 }
开发者ID:safaricco,项目名称:admfw,代码行数:33,代码来源:Login.php

示例7: test_can_create_user

 public function test_can_create_user()
 {
     $user = $this->createUser();
     $this->assertEquals('Test', $user->name);
     $this->assertEquals('test@test.com', $user->email);
     $this->assertTrue(Hash::check('123456', $user->password));
 }
开发者ID:netoudi,项目名称:laravel-tdd,代码行数:7,代码来源:AuthorizationRepositoryTest.php

示例8: login

 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);
     }
 }
开发者ID:48group,项目名称:Eastland-Server-Side,代码行数:29,代码来源:UserController.php

示例9: authenticate

 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);
     }
 }
开发者ID:Adrian-Vergara,项目名称:aesap_servidor,代码行数:30,代码来源:AuthenticateController.php

示例10: login

 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.'));
     }
 }
开发者ID:weopendata,项目名称:medea,代码行数:32,代码来源:AuthController.php

示例11: boot

 /**
  * 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;
     });
 }
开发者ID:playatech,项目名称:laravel-voldb,代码行数:35,代码来源:AppServiceProvider.php

示例12: test_can_create_user

 public function test_can_create_user()
 {
     $user = $this->app->make(UserRepositoryInterface::class)->create(['name' => 'Test', 'email' => 'test@test.com', 'password' => '123456']);
     $this->assertEquals('Test', $user->name);
     $this->assertEquals('test@test.com', $user->email);
     $this->assertTrue(Hash::check('123456', $user->password));
 }
开发者ID:netoudi,项目名称:laravel-tdd,代码行数:7,代码来源:MailTest.php

示例13: boot

 /**
  * 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();
     });
 }
开发者ID:bitller,项目名称:nova,代码行数:31,代码来源:AppServiceProvider.php

示例14: login

 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);
             }
         }
     }
 }
开发者ID:leloulight,项目名称:ext-app,代码行数:27,代码来源:AuthController.php

示例15: login

 /**
  * 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]]);
 }
开发者ID:Mathew78540,项目名称:both,代码行数:33,代码来源:AuthController.php


注:本文中的Illuminate\Support\Facades\Hash::check方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。