Laravel 5.5从密码重置表单中删除电子邮件字段

时间:2017-12-13 07:32:10

标签: email laravel-5.4 laravel-5.5 change-password forgot-password

我需要通过点击链接发送电子邮件,从用户来的密码重置表单中删除电子邮件字段。我不希望用户在休息密码期间再次重新输入电子邮件,因为他们已经验证了他们的电子邮件。这个问题已被多次询问,但大多数问题尚未得到解答,而其他问题则无效。我已经完成了这个讨论,但他们建议编辑非常危险的核心文件。所以有人找到了它的解决方案吗?

1 个答案:

答案 0 :(得分:3)

这是您手动创建重置令牌的方式

$email="example@gmail.com";
$token=hash_hmac('sha256', Str::random(40), env("APP_KEY"));
DB::table('password_resets')->where('email', '=', $email)->delete();
DB::table('password_resets')->insert(
        ['email' => $email, 'token' => bcrypt($token)]
    );

现在$token是通过url发送的令牌,bcrypt($token)是加密的令牌,保存在数据库中。

获得令牌后,您只需向用户发送电子邮件,其中包含http://website.com/password/newresetpage/{{$email}}/{{$token}}

等网址

在新的重置密码页面中,只需隐藏电子邮件字段,然后从网址设置$email字段。

<form class="form-horizontal" role="form" method="POST" action="{{ route('password.request') }}">
                        {{ csrf_field() }}

                        <input type="hidden" name="token" value="{{ $token }}">

                        <div class="form-group{{ $errors->has('email') ? ' has-error' : '' }}">
                            <label for="email" class="col-md-4 control-label">E-Mail Address</label>


                                <input id="email" type="email" class="form-control" name="email" value="{{$email}}" required hidden="true">


                        <div class="form-group{{ $errors->has('password') ? ' has-error' : '' }}">
                            <label for="password" class="col-md-4 control-label">Password</label>

                            <div class="col-md-6">
                                <input id="password" type="password" class="form-control" name="password" required>

                                @if ($errors->has('password'))
                                    <span class="help-block">
                                        <strong>{{ $errors->first('password') }}</strong>
                                    </span>
                                @endif
                            </div>
                        </div>

                        <div class="form-group{{ $errors->has('password_confirmation') ? ' has-error' : '' }}">
                            <label for="password-confirm" class="col-md-4 control-label">Confirm Password</label>
                            <div class="col-md-6">
                                <input id="password-confirm" type="password" class="form-control" name="password_confirmation" required>

                                @if ($errors->has('password_confirmation'))
                                    <span class="help-block">
                                        <strong>{{ $errors->first('password_confirmation') }}</strong>
                                    </span>
                                @endif
                            </div>
                        </div>

                        <div class="form-group">
                            <div class="col-md-6 col-md-offset-4">
                                <button type="submit" class="btn btn-primary">
                                    Reset Password
                                </button>
                            </div>
                        </div>
     </form>