How do i use 3/4 username in laravel 6.* or later version? - laravel

I stored data in user table like "id, name, username, phone_no, employee_no, email, password and many more columns.
I want to log in as Username & Password, email & Password, phone_no & Password, employee_no & Password.
what is the methodology need for this?
currently, I'm using a username & Password as laravel default.

Depending on your authentication method, you might need to override the function that looks for the user. But if you're asking for the query, typically you would do something like this:
User::where(function($query) {
$query->where('username', $accountIdentifier)
->orWhere('email', $accountIdentifier)
->orWhere('phone_number', $accountIdentifier)
->orWhere('employee_number', $accountIdentifier);
});
$accountIdentifier would correspond to the input of the user, which could be any of those parameters. It's also worth noting that I put it inside a sub-query because you might need to check for accounts that are active, or accounts that are verified.

Related

Getting the user by password reset token in Laravel without explicitly writing SQL query

I am developing a Laravel application. Now, I am trying to customise the password reset feature. I am trying to get the user by password reset token. I looked at the underlying database schema. There is a table called, password_resets. It has email, token and created_at columns. I can get the email of the user by token from that table. The thing is since there is no model created for that table, I will have to write the SQL query manually like this.
DB::select('SELECT * FROM password_resets WHERE token=?', [ $token ])
or the query builder
DB::table('password_resets')->where('token',$token)->first();
But I am trying to avoid using manual query. Is there a way to get the user by password reset token without writing manual SQL query?
DB::table('password_resets')->where('token',$token)->first();

Laravel 5.6 Auth from two different tables

I would like to ask about logging in to Laravel but in a different way:
User information including the password but not the email will be stored in users table, while email_address will be stored in a email_addresses table with a boolean field called is_default.
So the user can have several emails, but he can log in with only one email that has the is_default is true. and he could change his default email through his profile.
So, how can I make the login process through the Auth::login() facade.
I was able to register the user by storing the information in a users table and store his email_address and is_default = true in the email_addresses table.
It can be a little tricky. Auth::login() just needs to fetch email and password, so if you can trick the model into thinking it has an email field accessible via $user->email, things will work out:
public function getEmailAttribute()
{
return DB::table('email_addresses')->whhere('default', 1)->where('user_id', $this->id)->first()->toArray()['email'];
}

Laravel 5.4 reset password without email field

How I can get email from password_resets tabled based on token? Because I need remove email field from reset password view.
I tried DB::table() but its still returns empty items array.
What I'm doing wrong?
you can not select email using token. Because token is stored with Hashing, and every hash string generated from same token is different.
Laravel decrypt token by select it using email and then compare it with the plain token like this
if (Hash::check('plain_token', $hashed_token))
{
}
you can not do vice-versa.
hope, now you have clear the concept of reset password.
you can delete entries manually from database.

how to match hashed password in laravel4

I am working on change password function in laravel4 . I got stuck into one point that how to match hashed password on database with the new password we enter.
I know this that laravel4 Auth produces new hash value every time for the same input .
Please help me on this .
Thanks.
The question is unclear why do u want match the new password with old ?
But to check the password you can do
Hash:check($entered_old_password, $password_from_db);
*$password_from_db - would be hashed password.
I typically have a form with 3 text inputs, 1 for old password and 1 for new password and the last one for new password confirmation.
On submit check if the old password matchs if so update the user's password with the new one.
You can also use Eloquent Accessor & Mutators to Hash password every time it is set so you don't have to do that in multiple places
[http://laravel.com/docs/eloquent#accessors-and-mutators]
Is that what you are looking for?

CodeIgniter Tank Auth library: allow spaces in user name

Is there any way to allow spaces in user names Name Givenname and characters like ščťžýáíéúô (any UTF-8 characters) in CodeIgniter Tank Auth library?
I was browse code but I do not know hot to allow it? And aloso I need to allow duplicate usernames (need only email to be unique).
EDIT:
When I trying to register new user I get this error.
http://i.stack.imgur.com/jhxEO.png
I don't think Tank Auth places any restrictions on spaces/characters in the username, it's more likely to be the collation on your users table. Tank Auth uses SQL LOWER() functions to compare usernames to input, so SQL LOWER('whatever is in the DB') must equal PHP strtolower('whatever the user entered').
If your users table is not defined with collation UTF8_GENERAL_CI, try changing it to that.
If that doesn't fix it, the code in models/tank_auth/users.php is very simple, so you can easily adapt it to meet your needs.

Resources