WeBWorK Main Forum

Resetting admin password using Mysql

Resetting admin password using Mysql

by Thomas Hagedorn -
Number of replies: 2

After having to restart our server, mySQl wasn't running. After starting mySQl, we have the odd situation that the admin password isn't working. We are using Webwork 2.3.2. Looking at the files in the database, I find

1. a database "webwork_admin" with a table called "password" with 3 users: admin, hagedorn_Hagedorn_Linear, and clark_KarenTestCourse

2. a table called "admin_password" in the database "webwork". This table is empty.

When I run the newpassword command, it gives the error:

"Can't get password for user |admin| at ./newpassword line 85."

I presume, this is because the field is empty.

Everything else about the Webwork installation works fine. The admin password in the other courses works fine, and the courses are fine. But I can't create new courses without the admin password working.

I'm guessing that I need to run a mysql command to set the admin password. But I didn't find an exact example in the forum to copy, and I figured this wasn't a place to use trial and error. If a mysql command is the way to go, can someone send me it?

Thanks in advance,
Tom



In reply to Thomas Hagedorn

Re: Resetting admin password using Mysql

by Gavin LaRose -
Hi Tom,

My install is somewhat post 2.3.2, but I think this part of the database hasn't changed. I don't have a database called "webwork_admin". In the "webwork" database, I have a complete set of course tables ("{course}_key", "{course}_password", "{course}_permission", "{course}_problem", "{course}_problem_user", "{course}_set", "{course}_set_user", "{course}_user") for each course I've created, and also for the "admin" course.

The "admin" course is the one that you log in to to do course administration stuff. So, in mysql,
mysql> use webwork;
mysql> select * from `admin_password` where user_id='admin';
will tell you what the password is for the admin login (which you've indicated is blank). Similarly
mysql> select * from `Hagedorn_Linear_password` where user_id='hagedorn';
should select the password information for user "hagedorn" from the course "Hagedorn_Linear". The password should be some encrypted string that looks something like "abYCaNDljAXKo".

If you know the password for user "hagedorn" in the course "Hagedorn_Linear", one easy way of resetting the admin password would be to
mysql> update `admin_password` set password="abYCaNDljAXKo" where user_id='admin';
(where "abYCaNDljAXKo" is the encrypted string you had in the Hagedorn_Linear_password table), which will set the admin password to the same thing as hagedorn's password in Hagedorn_Linear.

Gavin
In reply to Gavin LaRose

Re: Resetting admin password using Mysql

by Thomas Hagedorn -

Thank you Gavin! I was able to use your post to repair the database. In case anyone else has this problem, here's what I did:

I used the following commands (where "..." indicates the values copied for admin from another course as Gavin indicated in his post):

INSERT INTO admin_key SET user_id="admin", key_not_a_keyword="...";
INSERT INTO admin_password SET user_id="admin", password="...";
INSERT INTO admin_permission SET user_id="admin", permission="10";
INSERT INTO admin_user SET user_id="admin", first_name="System", last_name="Administrator", email_address="webwork@yourschool.edu", student_id="admin", status="C",section="NULL", recitation="NULL",comment="NULL";

(By the way, the UPDATE command didn't work for me as "admin" wasn't even listed under admin_password, so I had to recreate the row before changing the password.)

Now I didn't do all this correctly the first time, so once the table admin_password had the row "admin" set up, I ran the command

newpassword admin admin your_password_here

in /webwork2/bin to change the admin password from the command line. If one runs the four commands above correctly, this last step might not be necessary.

So far, everything seems to be working fine. I've created/deleted a course using the Course Administrator page, so the admin account seems to be set up fine.

-Tom