Allow aliases to be entered in the authentication

Fix the authentication password check to allow "alias-accounts"
This commit is contained in:
Timothée Jaussoin 2021-04-27 17:24:27 +02:00
parent 9cf86e1b6a
commit c8aa86d77a

View file

@ -44,13 +44,22 @@ class AuthenticateController extends Controller
public function authenticate(Request $request)
{
$request->validate([
'username' => 'required|exists:external.accounts,username',
'username' => 'required',
'password' => 'required'
]);
$account = Account::where('username', $request->get('username'))
->first();
// Try alias
if (!$account) {
$alias = Alias::where('alias', $request->get('username'))->first();
if ($alias) {
$account = $alias->account;
}
}
if (!$account) {
return redirect()->back()->withErrors(['authentication' => 'The account doesn\'t exists']);
}
@ -59,7 +68,7 @@ class AuthenticateController extends Controller
foreach ($account->passwords as $password) {
if (hash_equals(
$password->password,
Utils::bchash($request->get('username'), $account->resolvedRealm, $request->get('password'), $password->algorithm)
Utils::bchash($account->username, $account->resolvedRealm, $request->get('password'), $password->algorithm)
)) {
Auth::login($account);
return redirect()->route('account.panel');