Login Using Email or Username

Re: Login Using Email or Username

by Anne Krijger -
Number of replies: 7

Two comments;

1. Why change core code when you can create an authentication plugin?
http://docs.moodle.org/dev/Authentication_plugins

2. AFAIK Moodle needs the user email address to be unique already.

Anne.

 

In reply to Anne Krijger

Re: Login Using Email or Username

by David Meuleman -

1.  From the page you linked:

a lot of interesting stuff happens in authenticate_user_login().

2.  It looks up the username in the mdl_user table to see if they are allowed to log in, and which authentication plugin handles their login requests. (This will be the plugin that handled their first-ever login request.)

I want my users to be able to use either their username or their e-mail address when they log in.  An authentication plugin won't help with this because the logic that needs "fixed" is in the core code.

2.  While it's true that the program won't allow you to use an e-mail address that is already in use, that doesn't mean it can't be changed in the database.  The e-mail field is not a unique field in my MySQL database.

In reply to David Meuleman

Re: Login Using Email or Username

by Anne Krijger -

Hi David,

In the default situation people can log in using their username.
So 50% of your requirement is already covered.

The other 50% is that if they do no use their username, but their email instead, they still should be able to log in.

So if it doesn't exists yet, you'd need to write a auth plugin that accepts the email address of a user and based on that checks against the password.

Because the auth plugins work via a failover/waterfall method; as long as one auth plugin does not authenticate the user the next auth plugin in line will be called, this will result in users begin able to either use their username or email to log in.

If there is a chance of email duplication (I seem to recall Moodle code really doesn't like that), you could make sure that in that case people or the admin get a warning.

Anne.

In reply to Anne Krijger

Re: Login Using Email or Username

by David Meuleman -

I spent this afternoon trying to write the plugin you suggest.

When Moodle successfully authenticates a user during the failover/waterfall portion of authenticate_user_login() after not finding the username in the user table, it attempts to create a new account.  The user already has an account, so it will likely fail because of duplicate users (or worse...it will actually create a new account and the user now has two!).

If you enable $CFG->authpreventaccountcreation to try to stop this behavior, it never gets to the failover/waterfall routine.

Dave

In reply to David Meuleman

Re: Login Using Email or Username

by Lael ... -

Has there been any progress with allowing users to login with their email address instead of username? Using emails as the login is both common and intelligent as it is self-validating each time the user logs in (oh.. my old email is what I'm using... I should change that...)

In reply to Lael ...

Re: Login Using Email or Username

by Mary Cooch -
Picture of Documentation writers Picture of Moodle HQ Picture of Particularly helpful Moodlers Picture of Testers Picture of Translators

From Moodle 2.7 you can log in with your email and  your username. I thought you could already log in with your email? But currently it is an "either/or" ; from 2.7  you can use both for logging in, whichever one you feel like using.

Average of ratings: Useful (2)
In reply to Mary Cooch

Re: Login Using Email or Username

by Bernhard Weichel -

Having the same issue, on Moodle 2.8 It does not work to login either by user name or by email. What am I doing wrong? Is there some adjustment to be made?

In reply to Bernhard Weichel

Re: Login Using Email or Username

by Gerald Grow -

In Moodle 2.7 and above, in order to have a username, but also be able to use your email address as the username, you have to check a box.

Go to Site Administration / Plugins / Auththentication / Manage Authentication, and check the box labeled "Allow log-in via email."

The label is a bit confusing, since you are not actually logging in via email, but are logging in by using your email address as your username, even when you already have a username that is something else. 

If this works as promised, you can instruct students that, if they forget their usernames, to use their email address instead.

Then they only have to remember which email address to use!