Secure Passwords Using Python

Hello, friends! In this tutorial, we are going to create a Python application to secure any password that you want for more security. So let’s get started!

Create Secure Passwords Using Python

Creating a strong password plays an important role in everyone’s life nowadays to keep your accounts more safe and secure. Simple and guessing passwords can be easily get hacked. To avoid this situation, we will learn how to generate your own safe and secure password using simple python code.

So before we start our code let’s discuss the concept behind it first. In this application, we are going to replace a bunch of characters with different symbols. i.e, $, &, @, 0, 1, | and etc.

So the basic idea behind this is to take the password as an input from the user and then replace its characters with symbols and then print the output for the new strong generated password for the user.

Source code:

SECURE = (('s', '$'), ('and', '&'), 
            ('a', '@'), ('o', '0'), ('i', '1'),
            ('I', '|'))

def securePassword(password):
    for a,b in SECURE:
        password = password.replace(a, b)
    return password

if __name__ == "__main__":
    password = input("Enter your password\n")
    password = securePassword(password)
    print(f"Your secure password is {password}")

From the above code, you can see that we have created a SECURE and replaced many characters with symbols in it. Then we defined a function and passed the password as an argument.  In it, we are replacing characters with symbols as listed in SECURE.  Then we have a section to take input from the user and to give them the new output as a new generated password.

Output 1:

Enter your password
Indians123
Your secure password is |nd1@n$123

Output 2:

Enter your password
I love India
Your secure password is | l0ve |nd1@

In the same way, we can create as many passwords as we want. We can replace characters with more symbols and numbers. You can use other tricks too like replacing a character with a string or replacing a string with a symbol and so on.

As you can see the results came out as expected. I tried to implement it in the simplest way possible. I hope you like it. If you have any doubts then please comment below.

Also read: Check for the standard password in Python using Sets

Leave a Reply

Your email address will not be published. Required fields are marked *