Skip to content
pakainfo

Pakainfo

Web Development & Good Online education

  • Home
  • Blog
  • Categories
  • Tools
  • Full Form
  • Guest Post
  • Advertise
  • About
  • Contact Us

authentication login with username or email in laravel

July 8, 2018 Pakainfo Laravel, Mysql, Mysqli, php, Programming Leave a comment

authentication login with username or email in laravel

Contents

  • authentication login with username or email in laravel
    • login with username or email in laravel 5 Example
    • login with username or email in laravel 5
    • laravel 5.3 or more version login with username or email Example
    • laravel Auth login with username or email
    • Related posts

login with username or email in laravel 5 Example

Laravel comes with simple store auth out-of-the-box authorization email or password mechanism which is simple security incredibly easy to use. But it all the depends on several pre-defined function or things, one of the simple main purpose ones – DB table of any users structure and mechanism for login with email address field. What if we want to have email or username to identify a clients?authentication login with username or email in laravel Example

login with username or email in laravel 5

    public function login(Request $request)
    {
        $field = filter_var($request->input('email_address_username'), FILTER_VALIDATE_EMAIL) ? 'email' : 'username';
        $request->merge([$field => $request->input('email_address_username')]);
        if (\Auth::attempt($request->only($field, 'password')))
        {
            return redirect('/');
        }
        return redirect('/login')->withErrors([
            'error' => 'These specific credentials have not match our admin panel records.',
        ]);
    }

Routing using Laravel

php artisan make:auth

laravel 5.3 or more version login with username or email Example

All we some need is add a just property in app/Http/AuthController.php:

protected $username = 'username';

 Illuminate\Foundation\Auth\AuthenticatesUsers.php
 
   public function postLogin(Request $request)
    {
        $this->validate($request, [
            $this->loginUsername() => 'required', 'password' => 'required',
        ]);

And then let’s look into loginUsername() method.

 
    public function loginUsername()
    {
        return property_exists($this, 'username') ? $this->username : 'email';
    }

laravel Auth login with username or email

	
	<form method="POST" action="/auth/login">
    {!! csrf_field() !!}

    <div>
        Email
        <input type="text" placeholder="username or email" name="username" value="{{ old('username') }}">
    </div>

    <div>
        Password
        <input type="password" placeholder="your strong password" name="password" id="password">
    </div>

    <div>
        <input type="checkbox" name="remember"> Remember Me
    </div>

    <div>
        <button type="submit">Login</button>
    </div>
</form>

and in we AuthenticatesAndRegisterUsers.php we can change email address to simple username also.

public function postLogin(Request $request_data)
{
	$this->validate($request_data, [
		'username' => 'required', 'password' => 'required',
	]);

	$credentials = $request_data->only('username', 'password');

	if ($this->auth->attempt($credentials, $request_data->has('remember')))
	{
		return redirect()->intended($this->redirectPath());
	}

	return redirect($this->loginPath())
				->withInput($request_data->only('username', 'remember'))
				->withErrors([
					'username' => $this->getFailedLoginMessage(),
				]);
}

Example

Related posts:

  1. html code for login page with username and password validation
  2. Login Signup with Laravel
  3. Setup Laravel 6 Login Authentication
  4. Laravel 5.7 Get Current UserId UserName and Email
  5. Laravel Custom Login Registration Example Tutorial
  6. Laravel 7 User Login Authentication From Scratch
  7. how to make a login page in html with database?
  8. PHP login logout script with session Example
  9. How to Setup Laravel 6 Login Authentication Tutorial
Also Read This πŸ‘‰   vuejs Simple calculator web Application
laravel 5 login and registration tutoriallaravel 5.2 login with usernamelaravel 5.3 login with username or emaillaravel 5.4 login with username or emaillaravel 5.5 login with usernamelaravel 5.5 login with username or emaillaravel 5.6 login with username or emaillaravel auth

Post navigation

Previous Post:Set dynamically Next Page Url Using JQuery DataTable
Next Post:Laravel Autocomplete text field suggestions search using Database

Advertise With Us

Increase visibility and sales with advertising. Let us promote you online.
Click Here

Write For Us

We’re accepting well-written informative guest posts and this is a great opportunity to collaborate.
Submit a guest post to [email protected]
Contact Us

Freelance web developer

Do you want to build a modern, lightweight, responsive website quickly?
Need a Website Or Web Application Contact : [email protected]
Note: Paid Service
Contact Me

Categories

3movierulz (64) Ajax (464) AngularJS (377) ASP.NET (61) Bio (109) Bollywood (108) Codeigniter (175) CSS (98) Earn Money (92) Education (61) Entertainment (130) fullform (86) Google Adsense (63) Highcharts (77) History (40) Hollywood (109) JavaScript (1359) Jobs (42) jQuery (1423) Laravel (1088) LifeStyle (53) movierulz4 (63) Mysql (1032) Mysqli (891) php (2127) Programming (2338) Python (98) Software (169) Software (88) Stories (98) tamilrockers (104) Tamilrockers kannada (64) Tamilrockers telugu (61) Tech (145) Technology (2395) Tips and Tricks (121) Tools (210) Top10 (491) Trading (92) Trending (73) VueJs (250) Web Technology (106) webtools (192) wordpress (166) World (333)

A To Z Full Forms

Access a complete full forms list with the meaning, definition, and example of the acronym or abbreviation.
Click Here
  • Home
  • About Us
  • Terms And Conditions
  • Write For Us
  • Advertise
  • Contact Us
  • Youtube Tag Extractor
  • Info Grepper
  • Guest Posting Sites
  • Increase Domain Authority
  • Social Media Marketing
  • Freelance web developer
  • Tools
Pakainfo 9-OLD, Ganesh Sco, Kothariya Ring Road, Chokadi, Rajkot - 360002 India
E-mail : [email protected]
Pakainfo

Β© 2023 Pakainfo. All rights reserved.

Top
Subscribe On YouTube : Download Source Code
We accept paid guest Posting on our Site : Guest Post Chat with Us On Skype Guest Posting Sites