On some occasions, to enter an application, website or simply to protect our important data, we use a type of protection that strengthens the stability of our information.
To limit access to a type of data or file, some of us use a password.
But what happens when we forget it due to some carelessness? For example, what would happen if we forget our email password?...
Fortunately, there are ways to recover or reset passwords if they are lost or forgotten.
To do this, several types of processes are carried out, depending on the application from which we want to restore.
In this case something very special happened to me, I installed Drupal on my Ubuntu 13.04 computer and created my administrator user with its respective password; Let us remember that users in Drupal are classified as follows: SuperUser (1), Authenticated User (2) and Visitor (3); Its status is also described as follows: Active (1) or Blocked (0).
From here we can add other types of users with the permissions and statuses that we deem relevant.
There are many ways to install Drupal on our computer, in my case I have Apache, PHP and MySQL installed on Linux.
While editing and configuring content, I did not believe the password was essential. When the day was over, I turned off my computer without closing the browser tabs. I did this so that when I turned it on again, only the restore message appeared and I continued with all the applications and tabs that I had opened. This saved me the trouble of opening them again. each tab with the information I needed.
One day my computer closed all the browser sessions. I didn't give it much importance, I just thought about reopening them with the information I needed, but when I got to the Drupal interface I realized the problem, I had forgotten the administrator password (Admin), after entering it incorrectly 5 times the user was blocked; But that was not the only problem, when I was in the process of installing Drupal, I had to enter an email to be able to reset the admin password, I actually didn't think it was so necessary because I thought I wouldn't forget my password and that I would configure it later.
Until then, the option of resetting the password by email was ruled out.
After trying several times without success, I achieved my goal, I found a very common way to do this type of operations.
The first thing is to Unlock my User,
I logged into MySQL from a terminal.
I wrote the MySQL login command:
$ mysql -u root -p
and then I entered my MySQL login password.
So, being inside the MySQL console, I wrote the following code:
mysql>show databases; and I pressed enter.
In this case my database is called user.
To use the user database, run the following line of code: use user;
Now it is time to see which tables this database contains, for this I used the command: show tables;
There I saw the tables that were inside the user database, and I found the users table that facilitated the process of recovering my password.
At this point I entered the following command:
select *from users; and press Enter.
Next I saw what type of information I was going to find and in what order I was going to see it.
The data I found was uid, name, pass.
uid: equivalent to the user identifier; administrator always equals the number 1.
name: Displays the name of the administrator user.
pass: this is what we are looking for, the password. In this case we will see it encrypted.
There, view the data of the user you wanted to recover, in this case Admin.
After this process, I wrote the following code in the terminal:
UPDATE users SET status=1 whereUID=1;
I pressed enter and waited for it to process
In this way we order the user UID=1: to go from state 0 (blocked) to state 1 (active).
The next step is to generate an automatic access url to reset the password, but before continuing we need to talk about the tool I am going to use. Drush (Drupal + Shell) is a Drupal command line shell that allows us to perform tasks such as installing, downloading or updating modules and many more functions.
To execute the following commands we must check that Drush is installed on our computer, in the same way if it is not installed, we do it as follows:
$ sudo apt-get install drush and press enter.
It only takes a few minutes, and when it finishes installing we can go ahead and run our code without any problems.
Concluding our password reset process, I opened a terminal, located myself in the path where I had my Drupal project and typed the following command.
$ drush uli and hit enter.
At the end of the process he showed me this:
To complete the process, a link has been generated to restore the password
What I did was copy from: /?q=user/… to where the url line ends.
In this case as I have Drupal installed on:
localhost and the access address is: localhost/drupal7
It will have to look like this:
localhost/drupal7/?q=user/reset/1/………./XT_vxbql………._E3CU305omej1gYCVnelWPL6Q/login
I copied and pasted this URL into the browser and hit enter.
It immediately redirects us to the password reset, where we must make sure to enter a password that we will not forget so easily or save it online with a password manager like: https://www.passpack.com/en/home/ and that's it.
Thanks to this experience I learned that passwords are very important, that I should keep them within reach and make a copy for security, in addition to that I put my knowledge in MySQL and Drush to the test to be able to reset my password.
By: Cesar Duran
Drupal Jr Developer
Seed EM