简体   繁体   English

如何仅使用用户名和密码在 laravel 中验证登录?

[英]how to authenticate login in laravel using only username and password?

I have a mysql database of users with only 2 field: username and password.我有一个 mysql 用户数据库,只有 2 个字段:用户名和密码。 I'm trying to build a login page but the authentication function I'm using always returns false, even if the username and password are correct.我正在尝试构建一个登录页面,但我使用的身份验证功能总是返回 false,即使用户名和密码是正确的。

my if statement is:我的 if 语句是:

if (auth()->attempt($formFields))

where:在哪里:

$formFields = $request->validate([
        'user' => 'required',
        'password' => 'required'
    ]);

I tried to check if the problem is in the input i'm getting but it looks fine.我试图检查问题是否出在我得到的输入中,但它看起来很好。 from what i found online it appears that this function uses email field to authenticate so i think this might be the problem, but i couldn't find anyway around that...从我在网上发现的情况来看,这个功能似乎使用电子邮件字段进行身份验证,所以我认为这可能是问题所在,但我无论如何都找不到......

Try to update your LoginController and put following function there.尝试更新您的 LoginController 并将以下功能放在那里。

public function username()
{
    $identity  = request()->get('identity');
    $fieldName = filter_var($identity, FILTER_VALIDATE_EMAIL) ? 'email' : 'user';
    request()->merge([$fieldName => $identity]);
    return $fieldName;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Laravel Passport:仅使用没有密码的用户名登录 - Laravel Passport: login using only username without password 如何仅在 Laravel 中使用 url 和 hash 参数登录? (没有用户名和密码) - How to login with url and hash parameter only in Laravel? (without username and password) 仅使用用户名登录wordpress - 无密码 - Login to wordpress using only a username - no password 使用HttpClient验证用户名和密码 - Using HttpClient to authenticate username and password 自动验证htaccess(401)用户名密码登录 - Auto authenticate a htaccess (401) username password login Laravel 5.1 - 验证用户名,密码和如果确认= 1 - Laravel 5.1 - Authenticate Username, Password AND if confirmed = 1 无法验证Laravel中的用户:“无效的用户名或密码” - Unable to authenticate a user in Laravel: 'invalid username or password' 如何在不使用用户名和密码的情况下使用Active Directory在PHP中对用户进行身份验证 - How to authenticate users in PHP using Active Directory without username and password 如何使用PHP应用程序验证HTTPS站点的用户名/密码? - how authenticate username /password of https site using php application? 如何使用登录名,密码和OpenSSL证书对登录进行身份验证? - how to Authenticate login using Login, password and OpenSSL certificate?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM