custom remember me and login without Auth? i want to use custome login and remember me in laravel how to do it?
any best suggestion please it's my login function ?
$aCheckUser = Users::SELECT("UserId","UserName","UserPassword", "UserFullName")
->where("UserName", $sUserName)
->where("UserStatus", 1)->first();
if( ! empty($aCheckUser))
{
$sUserName = $aCheckUser->UserName;
$hashedPassword = $aCheckUser->UserPassword;
if (Hash::check($dTempPassword, $hashedPassword))
return("success|Login Successful..!");
else
throw new \Exception('WrongCredentials');
}else
{
throw new \Exception('WrongCredentials');
}
@a4ashraf my password is hashed in db ? can i use this scenario ?
@a4ashraf i am using second db connection for login not default so Auth getting default connection ? middleware not working ?
The authentication chapter will cover how remember me works. Also how to manually setup.
@zahidgopang
as I understand, are you use the password for confirmation?
please share your complete user controller
but auth using default connection instead second connection , middleware not working for auth .can we force auth to use second DB connection instead default ?
@a4ashraf how to pass Hash password into this?
if (Auth::attempt(['UserName' => $sUserName, 'UserPassword' => $sPassword], $iRememberMe)) {
return("success|Login Successful..!");
}
i am checking
if (Hash::check($dTempPassword, $hashedPassword))
as i have stored hased password into db?
Have you used any of the laravel Auth scaffolding, or is this totally custom?
Laravel has a "manual" way already:
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
class LoginController extends Controller
{
/**
* Handle an authentication attempt.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function authenticate(Request $request)
{
$credentials = $request->only('email', 'password');
if (Auth::attempt($credentials)) {
$request->session()->regenerate();
return redirect()->intended('dashboard');
}
return back()->withErrors([
'email' => 'The provided credentials do not match our records.',
]);
}
}
See:
https://laravel.com/docs/8.x/authentication#authenticating-users
@jlrdw it's custom . i am unable to pass hashed password into this all because it's showing wrong credentials message.?
@zahidgopang
here is how you convert password in hash
$password = Hash::make('yourpassword');
@jlrdw this is already done i am unable to pass hashed passworod into laravel auth?
@zahidgopang
here is how you convert password in hash
$password = Hash::make('yourpassword');
Do you have the email and password in a users table.
And since manually doing this, you probably need to (after your) custom success, then login to laravel via:
https://laravel.com/docs/8.x/authentication#other-authentication-methods
Perhaps get id from table while checking an:
$id is id you get from users table:
Auth::loginUsingId($id);
But it will be so much easier to follow laravel conventions.
i have UserName instead email, and UserPassword instead password in users table
"Illuminate\Auth\SessionGuard::login(): Argument #1 ($user) must be of type Illuminate\Contracts\Auth\Authenticatable, string given
getting this error when using Auth::login($user, $remember = true);
Did you try how to retrieve the ID while logging in, and use it to login.
You might be missing some use statements in your controller.
Edit:
If B, then use your own session strategy.
If A, (and just suggestion) follow laravel documention on authentication.
Please sign in or create an account to participate in this conversation.