Create Safer Passwords using Python

Featured Img Secure Password

Hello, coders! In this tutorial, we are going to create a python program to make your passwords more safe and secure for your own security.

We all know that creating a strong password plays an important role in one’s life to keep your accounts and personal information safe and secure and prevent it from getting into the wrong hands.

Simple passwords can be easily get hacked so we need to make our passwords difficult to hack. In this application, we are going to replace a bunch of characters with different special symbols such as $, &, @, 0, 1, |, and many more to make your passwords difficult to hack.

The application will take your password as an input from the user and then replace its characters with the special symbols mentioned and then print the output for the new stronger password for the user.

Creating safe passwords using Python

To make the passwords more secure, we would first create a map that will store which character needs to replaced and by which special symbol.

In the next step, a function is created which will do all the replacements in the password entered by the user and then return the more secure password.

# 1. Mapping characters with the secret codes
SECRET_CODE = [('g', '$'), ('t', '&'), ('a', '@'), ('s', '0'), ('h', '1'),('l', '|')]

# 2. Creating a function which will return the stronger password
def secure_password(user_pass):
    for a,b in SECRET_CODE:
        user_pass = user_pass.replace(a, b)
    return user_pass

# 3. Taking the input of the user password
cur_pass = input("Enter your current password: \n")

# 4. Making the password more secure
new_pass = secure_password(cur_pass)
print(f"Your secure and safe password is {new_pass}")

Some Sample Outputs

The code given above will return a more secure password and the same can be seen in the two outputs given below.

Enter your current password: 
This is my generic password
Your secure and safe password is T1i0 i0 my $eneric [email protected]
Enter your current password: 
Please give me a strong password
Your secure and safe password is P|[email protected] $ive me @ 0&ron$ [email protected]


You can replace characters with more symbols or numbers according to your own preference and make passwords more tough to hack. I hope you liked the simple application.

Thank you for reading!