Secure Passwords Using Python

Secure Passwords Using Python

Creating a strong password is essential in everyone’s life nowadays in order to keep your accounts safe and secure. Passwords that are simple and easy to guess can be readily hacked. To avoid this problem, we’ll show you how to create your own safe and secure password using simple Python code.

Examples:

Example1:

Input:

Original Password  = Italian

Output:

The new modified password =  |t@l1@n

Example2:

Input:

Original Password = albertos

Output:

The new modified password = @lbert0$

Secure Passwords Using Python

Below are the ways to write a program that creates the secured passwords.

The best and excellent way to learn a java programming language is by practicing Simple Java Program Examples as it includes basic to advanced levels of concepts.

So, before we begin writing code, let’s first talk about the idea behind it. In this application, we will replace a number of characters with various symbols. $, &, @, 0, 1, |, and so on.

So the main idea is to accept the user’s password as input, replace its characters with symbols, and then publish the output for the new strong-produced password for the user.

Method #1: Using For Loop and Replace Function (Static Input)

Approach:

  • Give the password as static input and store it in a variable.
  • Create a function createSecurePassword() which accepts the given password as an argument and returns the secure password.
  • Pass the given password as an argument to createSecurePassword() function.
  • Take a variable(say secpassword) and create some random characters as tuple ((‘s’, ‘$’), (‘and’, ‘&’), (‘a’, ‘@’), (‘o’, ‘0’), (‘i’, ‘1’), (‘I’, ‘|’)).
  • Loop using two variables in the secpassword using For loop.
  • Replace the password with the two variables.
  • Return the modified Password.
  • Print the New Modified Password.
  • The Exit of the Program.

Below is the implementation:

# Take a variable(say secpassword) and create some random characters as tuple
# (('s', '$'), ('and', '&'), ('a', '@'), ('o', '0'), ('i', '1'), ('I', '|')).
secpassword = (('s', '$'), ('and', '&'),
               ('a', '@'), ('o', '0'), ('i', '1'),
               ('I', '|'))
# Create a function createSecurePassword() which accepts the given password
# as an argument and returns the secure password.


def createSecurePassword(givenpassword):
    # Loop using two variables in the secpassword using For loop.
    for m, n in secpassword:
      # Replace the password with the two variables.
        givenpassword = givenpassword.replace(m, n)
    # Return the modified Password.
    return givenpassword


# Give the password as static input and store it in a variable.
givenpassword = 'Italian'
print('The original Password = ', givenpassword)
# Pass the given password as an argument to createSecurePassword() function.
modifiedpassword = createSecurePassword(givenpassword)
# Print the New Modified Password.

print('The new modified password = ', modifiedpassword)

Output:

The original Password =  Italian
The new modified password =  |t@l1@n

Method #2: Using For Loop and Replace Function (User Input)

Approach:

  • Give the password as user input using the input() function and store it in a variable.
  • Create a function createSecurePassword() which accepts the given password as an argument and returns the secure password.
  • Pass the given password as an argument to createSecurePassword() function.
  • Take a variable(say secpassword) and create some random characters as tuple ((‘s’, ‘$’), (‘and’, ‘&’), (‘a’, ‘@’), (‘o’, ‘0’), (‘i’, ‘1’), (‘I’, ‘|’)).
  • Loop using two variables in the secpassword using For loop.
  • Replace the password with the two variables.
  • Return the modified Password.
  • Print the New Modified Password.
  • The Exit of the Program.

Below is the implementation:

# Take a variable(say secpassword) and create some random characters as tuple
# (('s', '$'), ('and', '&'), ('a', '@'), ('o', '0'), ('i', '1'), ('I', '|')).
secpassword = (('s', '$'), ('and', '&'),
               ('a', '@'), ('o', '0'), ('i', '1'),
               ('I', '|'))
# Create a function createSecurePassword() which accepts the given password
# as an argument and returns the secure password.


def createSecurePassword(givenpassword):
    # Loop using two variables in the secpassword using For loop.
    for m, n in secpassword:
      # Replace the password with the two variables.
        givenpassword = givenpassword.replace(m, n)
    # Return the modified Password.
    return givenpassword


# Give the password as user input using the input() function and store it in a variable.
givenpassword = input('Enter some random password = ')
print('The original Password = ', givenpassword)
# Pass the given password as an argument to createSecurePassword() function.
modifiedpassword = createSecurePassword(givenpassword)
# Print the New Modified Password.

print('The new modified password = ', modifiedpassword)

Output:

Enter some random password = albertos
The original Password = albertos
The new modified password = @lbert0$

Related Programs: