Import users from extern Dbase

Import users from extern Dbase

by Serge Broos -
Number of replies: 4

Hello I'm newbie ....
After a desperate search in all items: 

https://moodle.org/mod/forum/discuss.php?d=76581

https://stackoverflow.com/questions/22863527/how-does-moodle-encrypts-the-password

https://moodle.org/mod/forum/discuss.php?d=235504#p1023177

https://moodle.org/mod/forum/discuss.php?d=233687#p1015697

I look for help:
i want to import users from an external Dbase (Mysqli and php7) into Moodle 3.6.1
My pasword_hashing is Blowfish (I suppose) -> $paswoord = password_hash($paswoord,PASSWORD_DEFAULT);
Example: test -> $2y$10$wtUJttanMpQw611t55GvfO8yUEwpD/4l.ihBwwxLnj5UksTXfaHJq

Which is, I suppose the correct form for Moodle 3.6.1
When I export the fields (username, paswoord, firstname and lastname) by the plugin and I try to login into Moodle this does not work.
Although the connection is OK. I tried with plain text and a normal pasword and so i mange to login into moodle and in the moodle Dbase (mdl_users i see then 'not cached'.
I tried MD5, Sha1 and one-way encryption .... nothing works.
What am I doing wrong?????

I want that the paswords stay hashed in my Dbase not in the dbase from moodle.

Thanx a lot !!!


Average of ratings: -
In reply to Serge Broos

Re: Import users from extern Dbase

by Leon Stringer -
Picture of Core developers Picture of Particularly helpful Moodlers

For that kind of hash value you should select "Crypt one-way string hashing" for Password format.

I've tried this on my Moodle 3.6 site: I have another database with "$2y$10$wtUJttanMpQw611t55GvfO8yUEwpD/4l.ihBwwxLnj5UksTXfaHJq" in the password column for the user and I am able to log in with the password "test".

Apart from the hash setting I've used the defaults in the plugin settings, the external database is MariaDB, so I'm using "mysqli" too.

If this still doesn't work, maybe tell us more about your environment, e.g. operating system, PHP exact version, database exact version. If the external database is on a different server give those details too. Also give the exact message you get when the login attempt fails.

If you're comfortable working with the code you could sanity check your PHP environment on the Moodle server with a test script:

<?php
$hash = '$2y$10$wtUJttanMpQw611t55GvfO8yUEwpD/4l.ihBwwxLnj5UksTXfaHJq';
$passwd = 'test';

if (password_verify($passwd, $hash)) {
    echo "Password OK" . PHP_EOL;
} else {
    echo "Password mismatch" . PHP_EOL;
}

E.g. save this as password_verify.php and run it with php password_verify.php.

In reply to Leon Stringer

Re: Import users from extern Dbase

by Serge Broos -

Dear Leon,

Thanks for the reply. Yes, it works. I think that my mistake was that I copied the hashed password from a testpage and pasted it into a field from the table. When I hashed it immediately into the Dbase it worked in the way you described. Thanks a lot !

Another question: after the login the user is directeur to rage authentication page. Is there a way to skip it and go directly to the courses?

Greetings,

Serge

In reply to Serge Broos

Re: Import users from extern Dbase

by Leon Stringer -
Picture of Core developers Picture of Particularly helpful Moodlers

I don't know what page that is, can you include a screenshot (with any personal details removed)?

If they're being redirected to the user profile page, check that all the mandatory fields are being populated by the database, i.e. values for First name, Surname and Email address are being provided under Data mapping on the plugin settings page.

In reply to Leon Stringer

Re: Import users from extern Dbase

by Serge Broos -
That was indeed the page I mentioned.

I filed all the fields and indeed all problems were solved. Thanks for the help !

Greetings,