php - Compare input of 2 inputs if it's the same

81

I'm making a form for people the change their passwords and I have a new password and a repeat password field to double check the new password is typed the right way.

I just don't know how to make this, I did try some stuff from the internet but I can't seem to make it work.

These are the fields I have at the moment in my Vue file:

<div >
  <div >
   <div >
     <div >
      <label>Current password</label>
     </div>
     <div >
      <input id="password" type="password">
     </div>
   </div>
   <div >
     <div >
      <label for="newPassword">New password</label>
     </div>
     <div >
      <input id="newPassword"  type="password" >
     </div>
   </div>
   <div >
     <div >
      <label for="repeatPassword">Repeat password </label>
     </div>
     <div >
      <input id="repeatPassword" type="password">
     </div>
   </div>
   <div >
     <button type="button" v-on:click='changePassword'>Confirm</button>
   </div>
  </div>
</div>

php:

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use App\User;

class ProfileController extends Controller
{
    //
    public function getProfile(Request $request) {
        $user_late = $request -> user()->getTooLateCount();
        $user_noShow = $request -> user()->getNoShowCount();
        $user_strikes = ($user_late/3)+$user_noShow;

        return view('profile' , [
            'profileName' => $request->user()->name , 
            'profileEmail' => $request->user()->email,
            'strikes'=> $user_strikes
        ]);

    }


}
554

Answer

Solution:

Server side validation may contain a reference to the 'confirmed' rule of which will enforce that the passwords match.'password' => 'required|confirmed|min:6',

Rename the comparative field topassword_confirmation.

Don't forget to add the CSRF token if appropriate.

16

Answer

Solution:

Use Validation Confirmed

in your controller add validation

$request->validate([
    'password' => 'required|confirmed',
]);

in your blade add name to your input

<input id="newPassword"  name="password" type="password" >

<input id="newPassword"  name="password_confirmation" type="password" >

People are also looking for solutions to the problem: php - How to reload a users authorization

Source

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.