Skip to content

Commit 773f199

Browse files
password hashing utility added for hash algos like MD5, SHA-1...
1 parent a5c1e10 commit 773f199

File tree

2 files changed

+80
-0
lines changed

2 files changed

+80
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# Password Hashing Utility
2+
3+
The Password Hashing Utility is a Python script that allows users to hash their passwords using various hashing algorithms for secure storage and comparison. Hashing passwords is an essential security measure to protect sensitive user data.
4+
5+
## How to Use
6+
7+
1. Clone the repository or download the script file `password_hashing_utility.py`.
8+
9+
2. Run the script using Python (Python 3.x is recommended).
10+
11+
3. Enter the password you want to hash when prompted.
12+
13+
4. Choose the desired hashing algorithm (e.g., 'md5', 'sha256', etc.).
14+
15+
5. The script will display the hashed password as a hexadecimal string.
16+
17+
## Supported Hashing Algorithms
18+
19+
The utility supports the following hashing algorithms available in the `hashlib` library:
20+
21+
- MD5
22+
- SHA-1
23+
- SHA-224
24+
- SHA-256
25+
- SHA-384
26+
- SHA-512
27+
- And more...
28+
29+
Please note that MD5 and SHA-1 are considered less secure due to vulnerabilities, and it is recommended to use stronger algorithms like SHA-256 or SHA-512.
30+
31+
## Example
32+
33+
```bash
34+
$ python password_hashing_utility.py
35+
Password Hashing Utility
36+
------------------------
37+
Enter your password: MySecurePassword
38+
Choose the hashing algorithm (e.g., 'md5', 'sha256'): sha256
39+
40+
Hashed password (using SHA-256): c1ef01b69b3d0e60c91f1c52e2185ab2de548be9f03f64e7c2712d3efea45d9c
41+
```
42+
## Customization
43+
You can modify the algorithm variable in the script to choose a different hashing algorithm. Make sure to use one of the supported algorithms mentioned in the list above.
44+
45+
## Disclaimer
46+
This script provides a basic password hashing utility and is intended for educational purposes only. In real-world applications, consider using a password hashing library with additional security features, such as salting and multiple iterations (e.g., bcrypt, Argon2).
47+
48+
Always follow security best practices to protect user passwords and sensitive data.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import hashlib
2+
3+
def get_hashed_password(password, algorithm='sha256'):
4+
"""
5+
Hashes the input password using the specified hashing algorithm.
6+
7+
Args:
8+
password (str): The input password to be hashed.
9+
algorithm (str): The hashing algorithm to use (default is SHA-256).
10+
11+
Returns:
12+
str: The hashed password as a hexadecimal string.
13+
"""
14+
if algorithm not in hashlib.algorithms_available:
15+
raise ValueError(f"Unsupported hashing algorithm: {algorithm}")
16+
17+
hashed_password = hashlib.new(algorithm, password.encode()).hexdigest()
18+
return hashed_password
19+
20+
if __name__ == "__main__":
21+
print("Password Hashing Utility")
22+
print("------------------------")
23+
24+
password = input("Enter your password: ")
25+
26+
try:
27+
# You can choose the hashing algorithm here (e.g., 'md5', 'sha256', etc.)
28+
algorithm = 'sha256'
29+
hashed_password = get_hashed_password(password, algorithm)
30+
print(f"Hashed password (using {algorithm.upper()}): {hashed_password}")
31+
except ValueError as e:
32+
print(e)

0 commit comments

Comments
 (0)