Laravel 5.5 remove email field from password reset form

I need to remove email field from password reset form at which user come by clicking link send via email. I don't want users to re-type their email again during resting password as they have already verified their email. This question has been asked several times but most of the questions are not answered yet and others are not working. I have gone through this discussion but they suggest of editing core file which is very risky. So anyone found it's solution yet?

Upvotes: 0

Views: 1484

Answers (1)

Shubham Pokhriyal
Shubham Pokhriyal

Reputation: 512

This is the way you create a reset token manually

$email="[email protected]";
$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)]
    );

Now $token is the token which is sent via url and bcrypt($token) is the encrypted token which is saved in the database.

After getting token you can simply send email to user with url like http://website.com/password/newresetpage/{{$email}}/{{$token}}

In your new reset password page which will be same as previous one, just hide the email field and set the field by $email from the url.

<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>

Upvotes: 3

Related Questions