本文整理汇总了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);
}
示例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']);
}
}
示例3: validateCurrentPassword
public function validateCurrentPassword($attribute, $value, $parameters)
{
if (Hash::check($value, Auth::user()->password)) {
return true;
}
return false;
}
示例4: checkPassword
public function checkPassword($password)
{
if (Hash::check($password, $this->attributes['password'])) {
return true;
}
return false;
}
示例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;
}
示例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();
}
}
}
示例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));
}
示例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);
}
}
示例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);
}
}
示例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.'));
}
}
示例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;
});
}
示例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));
}
示例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();
});
}
示例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);
}
}
}
}
示例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]]);
}