i have tried everything, i really don't know where i am doing wrong but each time i log in, it returns false. here is the method to store users in the db:
public function store(CreateUserRequest $request)
{
$user = new User();
$password = str_random(10);
$password_hash = bcrypt($password);
$new_user = $user->create([
'first_name'=>$request->input('first_name'),
'last_name'=>$request->input('last_name'),
'email'=>$request->input('email'),
'fone_number'=>$request->input('fone'),
'password'=>$password_hash
]);
$new_user->permissions()->create(UserPermission::$default);
//send email to the user
Mail::send('admin.emails.auth.new_user',['new_user'=>$new_user,'password'=>$password],function($message) use ($new_user){
$message->to($new_user->email)
->from('lilgaetan88@gmail.com','Admin Pedagogia')
->subject("your password");
});
return redirect()->route('home')->with('Success',"mail sent");
}
the logincontroller
public function postLogin(LoginRequest $request){
$remember = ($request->has('remember')) ? true : false;
if(Auth::attempt($request->only(['email','password']),$remember)){
return redirect()->intended('/home');
}
return redirect()->route('login')->with('fail','email or password incorrect');
}
}
login.blade.php file:
<form class="login-form" action="{{route('post-login')}}" method="post">
@if(Session::has('fail'))
<div class="alert alert-danger">{{\Illuminate\Support\Facades\Session::get('fail')}}</div>
@endif
@if ($errors->has())
<div class="alert alert-danger">
@foreach ($errors->all() as $error)
{{ $error }}<br/>
@endforeach
</div>
@endif
<div class="login-wrap">
<p class="login-img"><i class="fa fa-lock"> Login Page</i></p>
<div class="input-group">
<span class="input-group-addon"><i class="fa fa-envelope"></i></span>
<input type="text" name="email" class="form-control" placeholder="E-mail" autofocus>
</div>
<div class="input-group">
<span class="input-group-addon"><i class="fa fa-key"></i></span>
<input type="password" name="password" class="form-control" placeholder="Password">
</div>
<label class="checkbox">
<input type="checkbox" name="remember"> Se souvenir de moi
<span class="pull-right "> <a href="#"> Mot de Passe Oublie?</a></span>
</label>
{!!Form::token()!!}
<button class="btn btn-primary btn-block" type="submit">Login</button>
</div>
</form>
when i dd(Hash::check($pssowrd,$new_user->password)), it returns always true, that means the hashed password was correct but the authentication still returns false
尝试在第6行删除remove bcrypt()
方法。我认为密码散列是在laravel中自动处理的,因此您不需要bcrypt($password)
。
One possible Error would be, you are supposed send an Associative array of data to the attempt method; not an indexed array. So i guess it would work fine if you did like this,
Auth::attempt(['email' => $request['email'], 'password' => $request['password']], $remember))
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.