Hi Moodlers, im asking for help!
i want that my users can authenticate through a personal number, but im not sure how to start. I have seen some functions like user_login or authenticate_user_login but u always need the password, and i dont have it.
To put it clear, the question is how to fully login moodle without using a password. Sugestions?
If the student's personal number is stored in mdl_user.idnumber, you might be able to use the "External Database" authentication plugin to do this. Just go to "Users->Authentication->Manage Authentication" to activate it.
The External Database auth plugin is designed to let you authenticate against data in a different database. But, it can just as easily be used to authenticate against a different column in Moodle's own database. Just set the database connection parameters to point to Moodle's database, set the table to "mdl_user", the username field to "username" and the password field to "idnumber".
If none of the existing auth plugins can achieve what you want, then you might want to write your own: http://docs.moodle.org/en/Development:Authentication_plugins . It's actually fairly simple, especially if you can copy one of the existing plugins as a starting point.
But before you do that, take a look at the existing authentication plugins and see if any of them fit your needs. In addition to the ones Moodle ships with, there's another dozen or so available from the Moodle plugins page - http://moodle.org/mod/data/view.php?id=6009
The External Database auth plugin is designed to let you authenticate against data in a different database. But, it can just as easily be used to authenticate against a different column in Moodle's own database. Just set the database connection parameters to point to Moodle's database, set the table to "mdl_user", the username field to "username" and the password field to "idnumber".
If none of the existing auth plugins can achieve what you want, then you might want to write your own: http://docs.moodle.org/en/Development:Authentication_plugins . It's actually fairly simple, especially if you can copy one of the existing plugins as a starting point.
But before you do that, take a look at the existing authentication plugins and see if any of them fit your needs. In addition to the ones Moodle ships with, there's another dozen or so available from the Moodle plugins page - http://moodle.org/mod/data/view.php?id=6009
Thank you Aaron, u helped me a lot but im afraid the question is not so easy. Should i explain me a little more...
Right now, when u create a user, u have to choose the authentication method for that user. However, i need my authentication method to be chosen dinamically, so when a user clicks in the login link he can either login via user/pass or via idnumber and only the idnumber, not using a user. Is there anyway to do that?
Right now, when u create a user, u have to choose the authentication method for that user. However, i need my authentication method to be chosen dinamically, so when a user clicks in the login link he can either login via user/pass or via idnumber and only the idnumber, not using a user. Is there anyway to do that?
So what you want, is for the same user to be able to log in with their username&password, or their idnumber? And the user can use either one each time they log in?
For a start you would probably want to use an alternative login URL so that you can have a page that presents the user with the option to enter username&password --or-- idnumber and no password. As for the backend, unfortunately I don't think any of the existing Moodle authentication plugins can handle this scenario. It might be possible to hack together a solution using the "External Database" plugin and some creative database views (something that has two rows for each user, maybe, with one having the username/password the other having the idnumber and null).
The problem is that you want a user to be able to log in by two different methods. Moodle user account creation is dynamic, with the unrecognized username run through each plugin until one of them accepts it and creates a new user or until it fails in all of them. But when a Moodle user account is created, it's marked with exactly one authentication plugin, and on subsequent login attempts only that one plugin will be used. Check out the "Overview of Moodle authentication process" section of http://docs.moodle.org/en/Development:Authentication_plugins.
So if you want to accept two different login methods for the same user, I'm sorry to say you'll probably need to write your own authentication plugin.
For a start you would probably want to use an alternative login URL so that you can have a page that presents the user with the option to enter username&password --or-- idnumber and no password. As for the backend, unfortunately I don't think any of the existing Moodle authentication plugins can handle this scenario. It might be possible to hack together a solution using the "External Database" plugin and some creative database views (something that has two rows for each user, maybe, with one having the username/password the other having the idnumber and null).
The problem is that you want a user to be able to log in by two different methods. Moodle user account creation is dynamic, with the unrecognized username run through each plugin until one of them accepts it and creates a new user or until it fails in all of them. But when a Moodle user account is created, it's marked with exactly one authentication plugin, and on subsequent login attempts only that one plugin will be used. Check out the "Overview of Moodle authentication process" section of http://docs.moodle.org/en/Development:Authentication_plugins.
So if you want to accept two different login methods for the same user, I'm sorry to say you'll probably need to write your own authentication plugin.
Thats exactly what i want Aaron, than you for your answer. Thats because some of our students have a personal card that can be inserted in a card reader, and the card contains their personal id number. So, we want the students who have access to that card to log in with the card, or, if they dont have it or simply dont want so use it, they can log ir with the user&pass that all the students have.
I have found a possible solution, lets see. I made my checks about data as normaly, key comes in the auth.php for the new authentication plugin called DE. I got a new for in the login/index.php so the user that have the card can choose the way to log in. if they choose to log in trought the card the $de will be 1.
if(isset($de) && $de=='1')
{
class auth_plugin_de extends auth_plugin_db
{
function user_login($username, $password)
{
return parent::user_login($username, $password);
}
}
}
else
{
class auth_plugin_de extends auth_plugin_manual
{
function user_login($username, $password)
{
return parent::user_login($username, $password);
}
}
}
As u see, and also as u recommended me previously im using the manual login if i havent got the $de==1, or if i have it i use the external db authentication plugin, wich allow me to use the personal id_number as the password (read before).
What do u guys think? Questions? Expected problems? Improvements? (sure there will be a lot)
Thank you Moodlers!
I have found a possible solution, lets see. I made my checks about data as normaly, key comes in the auth.php for the new authentication plugin called DE. I got a new for in the login/index.php so the user that have the card can choose the way to log in. if they choose to log in trought the card the $de will be 1.
if(isset($de) && $de=='1')
{
class auth_plugin_de extends auth_plugin_db
{
function user_login($username, $password)
{
return parent::user_login($username, $password);
}
}
}
else
{
class auth_plugin_de extends auth_plugin_manual
{
function user_login($username, $password)
{
return parent::user_login($username, $password);
}
}
}
As u see, and also as u recommended me previously im using the manual login if i havent got the $de==1, or if i have it i use the external db authentication plugin, wich allow me to use the personal id_number as the password (read before).
What do u guys think? Questions? Expected problems? Improvements? (sure there will be a lot)
Thank you Moodlers!
Hey, changed the code a bit(the previous one doesnt works)but the idea still the same. However, i'm facing my first big problem. As u see my users log in with the user&pass via the manual authentication plugin or with the idnumber via the external database authentication plugin(wich in facts points to the same database).
However, some times the external database authentication makes the password field blank into the database. Other times it changes the password to the md5 corresponding to the idnumber. I have tested it in a new moodle installation and also in another computer, and it still happens,so its nothing i have changed its the problem.
Is there any know issue about this??
However, some times the external database authentication makes the password field blank into the database. Other times it changes the password to the md5 corresponding to the idnumber. I have tested it in a new moodle installation and also in another computer, and it still happens,so its nothing i have changed its the problem.
Is there any know issue about this??