Calculate User's Encrypted Password

SQLSQLBeginner
Practice Now

Introduction

In this project, you will learn how to encrypt a user's password using the SHA function in MySQL. This is a common practice in web applications to securely store user passwords.

👀 Preview

Unfinished

🎯 Tasks

In this project, you will learn:

  • How to access the MySQL database using the sudo command without a password
  • How to use the SHA function to encrypt a password
  • How to save the SQL statement that encrypts the password into a script file

🏆 Achievements

After completing this project, you will be able to:

  • Encrypt user passwords using the SHA function in MySQL
  • Create a script file to automate the password encryption process
  • Understand the importance of securely storing user passwords in web applications

Skills Graph

%%%%{init: {'theme':'neutral'}}%%%% flowchart RL mysql(("`MySQL`")) -.-> mysql/BasicKeywordsandStatementsGroup(["`Basic Keywords and Statements`"]) sql(("`SQL`")) -.-> sql/BasicSQLCommandsGroup(["`Basic SQL Commands`"]) sql(("`SQL`")) -.-> sql/DataManipulationandQueryingGroup(["`Data Manipulation and Querying`"]) mysql/BasicKeywordsandStatementsGroup -.-> mysql/source("`External Code Execution`") sql/BasicSQLCommandsGroup -.-> sql/select("`SELECT statements`") sql/DataManipulationandQueryingGroup -.-> sql/in("`IN clause`") mysql/BasicKeywordsandStatementsGroup -.-> mysql/select("`Data Retrieval`") mysql/BasicKeywordsandStatementsGroup -.-> mysql/use_database("`Database Selection`") subgraph Lab Skills mysql/source -.-> lab-301290{{"`Calculate User's Encrypted Password`"}} sql/select -.-> lab-301290{{"`Calculate User's Encrypted Password`"}} sql/in -.-> lab-301290{{"`Calculate User's Encrypted Password`"}} mysql/select -.-> lab-301290{{"`Calculate User's Encrypted Password`"}} mysql/use_database -.-> lab-301290{{"`Calculate User's Encrypted Password`"}} end

Access MySQL

In this step, you will learn how to access the MySQL database using the sudo command without any password.

  1. Open a terminal on your system.
  2. Run the following command to start the MySQL service:
sudo service mysql start
  1. Now, run the following command to access the MySQL client:
sudo mysql

This will allow you to access the MySQL database without any password.

Encrypt Jane's Password

In this step, you will learn how to encrypt Jane's password using the SHA function and display the encrypted password.

  1. Inside the MySQL client, run the following SQL statement:
SELECT SHA('jane1234') AS `Password`;

This statement will use the SHA function to encrypt the password 'jane1234' and display the encrypted password with the alias 'Password'.

Save the Script

In this step, you will save the SQL statement into a script file.

  1. Create a new file named shaPassword.sql in the /home/labex/project directory using your preferred text editor.

  2. Add the following SQL statement to the file:

    SELECT SHA('jane1234') AS `Password`;
  3. Save the file.

    Now, you have completed the project. You can run the script in the MySQL client using the following command:

    SOURCE /home/labex/project/shaPassword.sql;

    This will execute the SQL statement and display the encrypted password.

You can refer to the following output:

MariaDB [(none)]> SOURCE /home/labex/project/shaPassword.sql;
+------------------------------------------+
| Password                                 |
+------------------------------------------+
| b83755992eaa20453a0cd68fc01837c2422a6886 |
+------------------------------------------+
1 row in set (0.000 sec)
✨ Check Solution and Practice

Summary

Congratulations! You have completed this project. You can practice more labs in LabEx to improve your skills.

Other SQL Tutorials you may like