Get decrypted value from DB while doing where - laravel

I have a field email in my users table that is encrypted (with Crypt::encryptString method).
I need to retrieve user by email, so I can use this for example: $user = User::where('email', $email)->first(). But I need to find an encrypted mail. I'd like to decrypt the value while doing the where condition. I don't know if it's possible.

Related

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

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.

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 store password field in oracle 11g database in encrypted form?

I have a table in database with this structure:
Username
Password
Age
email
Address
Phone Number
I want to store this table's data manually(not by an input from a program) in the data base so that i can fetch it later for further use.
I want to store the password in the database in the encrypted form so that nobody can see the password.
How can i do this ?
I think you can go to the following site and check it out:-
http://docs.oracle.com/cd/E18283_01/network.112/e10746/asotrans.htm
You can use Master Encryption Key.It is implemented in a lot of places where user details should not be misused such as credit card no.

Resources