c# problems generating a password

c# problems generating a password

by Mike Greineder -
Number of replies: 1

We are currently using Moodle 3.0.3+.  I am trying to manually insert users into the mysql database as a part of a sync process with another system.  I am able to insert the user record, but I am having problems getting the password correct.  My SQL statement is as follows:

comm.CommandText = "insert into mdl_user (auth, confirmed, mnethostid, username, password, firstname, lastname, email, phone1, address, city, country) ";

comm.CommandText += "values (@auth,@confirmed,@mnethostid,@username,md5(@password),@firstname,@lastname,@email, @phone1, @address, @city, @country)";

comm.Parameters.AddWithValue("@auth", "manual");

comm.Parameters.AddWithValue("@confirmed", 1);

comm.Parameters.AddWithValue("@mnethostid", 1);

comm.Parameters.AddWithValue("@username", username);

comm.Parameters.AddWithValue("@password", password);

comm.Parameters.AddWithValue("@firstname", FirstName);

comm.Parameters.AddWithValue("@lastname", LastName);

comm.Parameters.AddWithValue("@email", Email);

comm.Parameters.AddWithValue("@phone1", Phone);

comm.Parameters.AddWithValue("@address", AddressStreet1);

comm.Parameters.AddWithValue("@city", AddressCity);

comm.Parameters.AddWithValue("@country", "US");

The user inserts successfully, but I can't log in with the username and password.  I checked our config file and it does have a passwordsaltmain value, so I tried md5(@password + @salt) and it still doesn't work.

Any help would be greatly appreciated.


Mike

Average of ratings: -
In reply to Mike Greineder

Re: c# problems generating a password

by Leandro Mitsuyuki -

Hi, Mike

Moodle uses the function hash_internal_user_password()  defined at /lib/moodlelib.php to generate the hash on php. You should give a look at this function, that may be helpful.