1

I want to compare the password from the inputfield with the entry in the database. If the input from the user is correct he will get redirected. If its wrong nothing should happen.

I have this code in my Controller:

   public function check(check $check){

   if (User::where('password', '=', Input::get('password'))->exists()) {

      return redirect()->route('site.create');

   }

   Site::return($request->all());
}

And something like this stands in my view:

<div class="form-group row">
    <label for="password" class="col-md-4 col-form-label text-md-right">{{ __('please type in your password') }}</label>
<div class="col-md-6">
    <input id="password" type="password" class="form-control" name="password" required>

Thank you for every help i appreciate it.

3
  • Use Laravel's built-in Auth to handle users and passwords Commented May 23, 2018 at 8:00
  • I only want to check a password. I dont want to log in users Commented May 23, 2018 at 8:03
  • Are you inserting the passwords in database as it is or in hashes? Commented May 23, 2018 at 8:05

2 Answers 2

1

You cannot directly compare passwords in Laravel. Passwords are one way hashed only.

Hash::check('plain-text', $hashedPassword);

For more information https://laravel.com/docs/5.6/hashing

$user =  User::where('email', '=', Input::get('email'))->first();

if( Hash::check(Input::get('password'), $user->password)){
//passwrd is equal

}

If you just want to check the passwrd you can use Hash

If you want to logged in users directly with password.

if (Auth::attempt(['password' => $password])) {
    // Password matches and logged in.
}
Sign up to request clarification or add additional context in comments.

1 Comment

You're checking the email againts the password.
1

Try to use this:

if (Hash::check('yourpassword', Input::get('password'))) {
    return redirect()->route('site.create');
}

You can also use:

password_verify() in PHP. See this link: http://php.net/manual/en/function.password-verify.php

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.