我在做PHP Laravel身份驗證。註冊和電子郵件激活似乎效果很好。但是當登錄時,它總是返回false。我不知道這件事。我的電子郵件,密碼和活動列在我的數據庫中似乎正確。登錄認證總是失敗
用戶模態
class User extends Eloquent implements UserInterface, RemindableInterface {
protected $fillable = array('email', 'username', 'password', 'password_temp', 'code', 'active');
use UserTrait, RemindableTrait;
/**
* The database table used by the model.
*
* @var string
*/
protected $table = 'users';
/**
* The attributes excluded from the model's JSON form.
*
* @var array
*/
protected $hidden = array('password', 'remember_token');
}
的login.php
<form action="{{ URL::route('login-post')}}" method="post">
<!--/ sign in title-->
<!--text field-->
<div class="form-group">
<input type="email" name="email" placeholder="Email" class="form-control rounded input-lg text-center no-border" {{ (Input::old('email') ? ' value="'.Input::old('email') . '"' : '') }}>
@if($errors->has('email'))
{{ $errors->first('email') }}
@endif
</div>
<div class="form-group">
<input type="password" name="password" placeholder="Password" class="form-control rounded input-lg text-center no-border" {{ (Input::old('password') ? ' value="'.Input::old('password') . '"' : '') }}>
@if($errors->has('password'))
{{ $errors->first('password') }}
@endif
</div>
<!--/ text field-->
<div class="text-center m-t m-b">
<input type="checkbox" name="remember" id="remember">
<label for="remember">
Remember Me
</label>
</div>
<input type="submit" value="Sign in" class="btn btn-lg btn-warning lt b-white b-2x btn-block btn-rounded"></input>
{{ Form::token() }}
</form>
控制器
public function postSignIn() {
$validator = Validator::make(Input::all(),
array(
'email' => 'required|email',
'password' => 'required'
)
);
if ($validator->fails()) {
return Redirect::route('login')
->withErrors($validator)
->withInput();
}else {
$remember = (Input::has('remember')) ? true : false;
//Attempt user sign-in
$auth = Auth::attempt(array(
'email' => Input::get('email'),
'password' => Input::get('password'),
'active' => 1
), $remember);
if ($auth) {
//Redirect to the intended page
return Redirect::intended('home');
}else {
return Redirect::route('login')
->with('global','Email/Password is wrong or account is not activated.'.Hash::make(Input::get('password')));
}
}
return Redirect::route('login')
->with('global','There was a problem signing you in.');
}
問題 它總是返回不正確的密碼。
解決方案 Laravel的數據庫密碼長度必須至少爲60。
當你將密碼存入數據庫時,你做了Hash :: make()嗎? – goldlife
@goldlife是的,我有存儲在數據庫之前的hash :: make我的pas thsword。 – AndroidBeginner
你有 ''driver'=>'eloquent','model'=>'User','table'=>'users',' 在你的config/auth.php中? – goldlife