Click here to Skip to main content
15,886,833 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have create 1 username : ABC and password : abc123 in MYSQL db, i try to login with abc(username) & ABC123(password) and its managed to login.

And i want to make the username as case insensitive which i can login with lower and upper case and the password i want to make it as case sensitive which i need to type exactly like what i've stored in db

What I have tried:

i try this method but still able to login

 public function login(Request $request)
{

 $check =  DB::table('user')->where('LoginID', strtolower($request->input('username')))->where('Password',$request-
 >input('password'))->get();

}
Posted
Updated 26-Aug-20 20:22pm
Comments
Richard MacCutchan 27-Aug-20 5:21am    
Both username and password should always be case sensitive for security.

Username is easy: store it in all lower case (in a second field if necessary) and just compare it.

But the password is more complex, because what you are doing is wrong, and could be very expensive for you. Never store passwords in clear text - it is a major security risk. There is some information on how to do it here: Password Storage: How to do it.[^] - ignore the code, it's C# based - but the text is still relevant. PHP provides easy to use password hashing functions: Hashing Passwords with the PHP 5.5 Password Hashing API[^] and you really should use them.

And remember: if this is web based and you have any European Union users then GDPR applies and that means you need to handle passwords as sensitive data and store them in a safe and secure manner. Text is neither of those and the fines can be .... um ... outstanding. In December 2018 a German company received a relatively low fine of €20,000 for just that.
 
Share this answer
 
Believe this is for learning aspect and you would follow best practices.

Try:
PHP
protected function login(Request $request)
{
    $credentials = [
        $this->username() => strtolower($request->input($this->username())),
        'password' => $request->get('password'),
    ];
    
    return $credentials;
}

More details here: How to make email login case insensitive with Laravel 5.5 authentication[^]
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900