TCBarrett

Open Source Architect (Web Geek)

Main menu

Skip to primary content
Skip to secondary content
  • Home
  • WordPress Info
    • WordPress Website
    • How To Get WordPress
  • WordPress Plugins
    • WP Glossary
      • How To Add Glossary Terms
      • Basic Usage Of The Glossary Shortcode
      • How To Make An A to Z Of Glossary Items
      • How To Make A List Of All My Terms
      • How To Turn Off Tooltips
      • How To Create Multiple Glossaries
      • How Do I Enable Comments
  • About Me
    • Open Source Architect
  • Contact
    • Donate
  • Glossary
    • Glossary A to Z
    • Glossary Term List
  • Login

Tag Archives: E-Mail

Allow WordPress login using Email Address

Posted on 2011/12/10 (557 days ago) by TCBarrett

WordPress usernames are unique. And by default, so are email addresses. I would recommend against changing this behaviour (see below for details). People remember their email addresses more readily than their usernames, so using their email address to log in is very useful.

Replace authenticate filter to allow email login

remove_filter( 'authenticate', 'wp_authenticate_username_password', 20, 3 );
add_filter( 'authenticate', 'tcb_authenticate_username_password', 20, 3 );
function tcb_authenticate_username_password( $user, $username, $password ) {
  if ( ! empty( $username ) && is_email( $username ) ) :
    if ( $user = get_user_by_email( $username )
      $username = $user->user_login;
  endif;

  return wp_authenticate_username_password( null, $username, $password );
}

This works by checking if the username supplied is an email address. If it is, then it finds the username associated with the email and uses that for authentication.

Multiple accounts per email

Although it is possible to allow multiple accounts per email address, it further complicates other core functions. Most importantly, the core password reset method assumes unique emails. The code above will not work in this case.

Posted in WordPress | Tagged Auth, E-Mail, Login

Get In Touch

Want to ask me a question? Tell me something? Or hire me? Send me a message using my contact form.

ADVERTISEMENT

Subscribe to my feed:

RSS Feed RSS - Posts

Recent Comments

  • Alex on WP Glossary – Basic Usage Of The Glossary Shortcode
  • Alex on WP Glossary – Basic Usage Of The Glossary Shortcode
  • mkhuda on My WordPress Incoming Links Dashboard Widget Is Empty
  • Bharath on WP Glossary WordPress Plugin – 10,000 Downloads
  • Jeremy Myers on My WordPress Incoming Links Dashboard Widget Is Empty

Networking

  • Facebook
  • Google +
  • LinkedIn
  • Pastebin
  • Tumblr (An Ode to Woody)
  • Twitter
  • Zerply

RSS Get The Latest (F1)

  • Mercedes & Pirelli face test hearing
  • Indian GP denies race is at risk

My sparse calendar

June 2013
M T W T F S S
« May    
 12
3456789
10111213141516
17181920212223
24252627282930

Enter your email address to subscribe to this blog and receive notifications of new posts by email.

RSS Angry Musings

  • Google – I hate their wafty design and crappy scroll bars
  • Those whiny cyclists are their own worst enemy

Follow me on Twitter

My Tweets

My favourite PAYG SIM

Get a free giffgaff Sim

Random Glossary Term

  • WordPress Foundation

ADVERTISEMENT

Proudly powered by WordPress