Calculate User's Encrypted Password

MySQLMySQLBeginner
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

Preview of MySQL encryption process

๐ŸŽฏ 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/TransactionManagementandSecurityGroup(["`Transaction Management and Security`"]) mysql(("`MySQL`")) -.-> mysql/BasicKeywordsandStatementsGroup(["`Basic Keywords and Statements`"]) mysql(("`MySQL`")) -.-> mysql/SystemManagementToolsGroup(["`System Management Tools`"]) mysql(("`MySQL`")) -.-> mysql/DatabaseFunctionsandDataTypesGroup(["`Database Functions and Data Types`"]) mysql/TransactionManagementandSecurityGroup -.-> mysql/identified_by("`User Authentication`") mysql/BasicKeywordsandStatementsGroup -.-> mysql/source("`External Code Execution`") mysql/SystemManagementToolsGroup -.-> mysql/mysqladmin("`Admin Utility`") mysql/DatabaseFunctionsandDataTypesGroup -.-> mysql/database("`DB Function - Info Retrieval`") mysql/DatabaseFunctionsandDataTypesGroup -.-> mysql/user("`User Info Function`") mysql/BasicKeywordsandStatementsGroup -.-> mysql/select("`Data Retrieval`") mysql/BasicKeywordsandStatementsGroup -.-> mysql/use_database("`Database Selection`") subgraph Lab Skills mysql/identified_by -.-> lab-301290{{"`Calculate User's Encrypted Password`"}} mysql/source -.-> lab-301290{{"`Calculate User's Encrypted Password`"}} mysql/mysqladmin -.-> lab-301290{{"`Calculate User's Encrypted Password`"}} mysql/database -.-> lab-301290{{"`Calculate User's Encrypted Password`"}} mysql/user -.-> 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 MySQL Tutorials you may like