我创建了客户端注册和密码更改功能。当我用密码注册客户端时,密码和用户名正在工作,没有任何问题。但是当我更改密码并使用新密码登录时,总是说密码不正确。我不明白是什么问题,请帮助我解决这个问题。
这是我的注册码
public function store(Request $request, client $client)
{
$token = $request->input('g-recaptcha-response');
if(strlen($token)>0)
{
$result = client::where('email', $request->email)->first();
if (!empty($result))
{
return Redirect::back()->with('errmessage','The registered email address is already in use. Please contact the website administrator or request a password reset');
}
$client->clie_id = $request->email;
$client->clie_fname = $request->clie_fname;
$client->clie_lname = $request->clie_lname;
$client->clie_company = $request->clie_company;
$client->password = Hash::make($request->password);
$client->email = $request->email;
$client->clie_telephone = $request->clie_telephone;
$client->clie_fax = $request->clie_fax;
$client->clie_address1 = $request->clie_address1;
$client->clie_address2 = $request->clie_address2;
$client->clie_address3 = $request->clie_address3;
$client->clie_city = $request->clie_city;
$client->clie_state = $request->clie_state;
$client->clie_postcode = $request->clie_postcode;
$client->clie_country = $request->clie_country;
$client->clie_newslatter= $request->clie_newslatter;
$client->save();
return Redirect::back()->with('message','Account Created Successfully. You may now login using the email you registered with and your password');
}else{
return redirect()->back()->with('warmessage','Please make sure your not a robot');
}
}
这是我的密码修改功能
public function PasswordChange(Request $request)
{
//dd($request->clientId);
$token = $request->input('g-recaptcha-response');
if(strlen($token)>0)
{
$user = Client::where('email', $request->clientId)->first();
if (!$user) {
return redirect()->back()->with('error', 'User not found.');
}
if (!Hash::check($request->old_password, $user->password)) {
return redirect()->back()->with('error', 'The old password is incorrect.');
}
$user->update([
'password' => Hash::make($request->password)
]);
// Clear the user's session to ensure the new password takes effect
Auth::guard('client')->logout();
return redirect()->route('Home')->with('message','Password is Successfully changed.');
}else{
return redirect()->back()->with('message','Please make sure your not a robot');
}
// return redirect()->route('home')->with('success', 'Password changed successfully.');
}
我的登录功能
public function login(Request $request)
{
//dd($request->password);
// Retrieve the user record by email
$user = client::where('email', $request->email)->first();
Log::info('Login attempt:', [
'email' => $request->email,
'entered_org_password' => $request->password,
'entered_password' => Hash::make($request->password),
'hashed_password' => $user->password,
]);
if(Auth::guard('client')->attempt(['email'=>$request->email,'password'=>$request->password],$request->remember))
{
return redirect('/')->withMessage('Successfully Logged In');
}else{
return redirect(route('Client_Login'))->with('Error');
}
return redirect()->back()->withInput($request->only('email'));
}
这是我的Modal
<?php
namespace App;
use Illuminate\Notifications\Notifiable;
use Illuminate\Foundation\Auth\User as Authenticatable;
class client extends Authenticatable
{
use Notifiable;
protected $guard = 'client';
protected $table='clients';
public function getAuthPassword()
{
return $this->password;
}
protected $fillable = ['email', 'password'];
protected $hidden = [
'password', 'remember_token',
];
}
这是我使用新密码登录时的日志数据
注册后,此记录用于登录。
[2023-10-05 08:34:06] local.INFO: Login attempt: {"email":"[email protected]","entered_org_password":"123456789","entered_password":"$2y$10$1mR2dKLEJAHvv0BCQoCfZeLP5Ugq4ngTvHD4/RFDtXp.asB7AJKF.","hashed_password":"$2y$10$Jxm/cd25Xpe4i8ljfDV98uIICszGb61pV6PtcwuhqHayjujWsOejm"}
更改密码和登录记录后
[2023-10-05 08:35:21] local.INFO: Login attempt: {"email":"[email protected]","entered_org_password":"123456789123","entered_password":"$2y$10$49D4RS5aNWwl8xtnWOGeQ.wuT2Ozipz4O1yAtmJQAsmjoZiLQb3b.","hashed_password":"$2y$10$.dj8Egmzr0JDs7IlmMfZ2ultD5Srp5YTo0Wxi0WHmxscc0P1cpS3u"}
我的密码更改表单输入
<form action="{{route('PasswordChange')}}" method="POST">
<input type="hidden" name="_token" value="{{ csrf_token() }}">
<div class="form-fields">
<div class="inputs">
<label for="Email">Old Password</label>
<input class="email" placeholder="Old Password" id="old_password" name="old_password" type="password"/>
<input type="hidden" name="clientId" id="clientId" value="{{$clients->email}}">
</div>
<div class="inputs">
<label for="Email">New Password</label>
<input class="email" placeholder="New Password" id="new_password" name="new_password" type="password"/>
</div>
<div class="inputs">
<label for="Email">Confirm Password</label>
<input class="email" placeholder="Confirm Password" id="confirm_password" name="confirm_password" type="password"/>
</div>
</div>
<div class="buttons">
<input class="button-1 login-button" type="submit" value="Update" style="width: 25%;"/>
</div>
</form>
这是我的登录页面输入
<form action="{{route('Client_Login.submit')}}" method="post">
@csrf
<div class="form-fields">
<div class="message-error">
</div>
<div class="inputs">
<label for="Email">Email:</label>
<input id="email" name="email" type="text"/>
</div>
<div class="inputs">
<label for="Password">Password:</label>
<input class="password" id="password" name="password" type="password" />
<span class="field-validation-valid" data-valmsg-for="Password" data-valmsg-replace="true"></span>
</div>
<div class="inputs reversed">
<label for="RememberMe">
<input class="form-check-input" type="checkbox" name="remember" id="remember" {{ old('remember') ?'checked' : 'checked'}}> Remember Me
</label>
<span class="forgot-password">
<a href="#">Forgot password?</a>
</span>
<span class="forgot-password">
|
</span>
<span class="forgot-password">
<a href="{{route('FrontClient.index')}}">Register</a>
</span>
</div>
</div>
<div class="buttons">
<input class="button-1 login-button" type="submit" value="Log in" />
</div>
</form>
2条答案
按热度按时间xuo3flqw1#
不确定你使用的是Laravel 5还是最新版本,但密码可能是双重哈希的。
在最新的Laravel版本中,有:
但假设你不使用它,你可能有
setPasswordAttribute
在User
模型,散列密码。因此,在
PasswordChange
方法中,您可能需要更改成
e0bqpujr2#
您的更新代码正在查找名为
password
的输入。您的表单具有名为old_password
、new_password
和confirm_password
的输入。您正在散列null
:我建议使用名为
old_password
,password
,password_confirmation
的输入并使用验证。confirmed
验证规则已存在,并且对于名为password
的字段的确认输入的名称,该规则需要password_confirmation
。