Python Extras
Password Authentication using Python
Password Authentication using Python
To create a password authentication system using Python you have to follow the steps mentioned below:
- Create a dictionary of usernames with their passwords.
- Then you have to ask for user input as the username by using the input function in Python.
- Then you have to use the getpass module in Python to ask for user input as the password. Here we are using the getpass module instead of the input function to make sure that the user doesn’t get to see what he/she write in the password field.
So let’s follow the steps mentioned above to create a password authentication system using Python:
import getpass | |
2 | database = {“aman.kharwal”: “123456”, “kharwal.aman”: “654321”} |
3 | username = input(“Enter Your Username : “) |
4 | password = getpass.getpass(“Enter Your Password : “) |
5 | for i in database.keys(): |
6 | if username == i: |
7 | while password != database.get(i): |
8 | password = getpass.getpass(“Enter Your Password Again : “) |
9 | break |
10 | print(“Verified”) |
Enter Your Username : aman.kharwal Enter Your Password : ·········· Enter Your Password Again : ·········· Enter Your Password Again : ·········· Verified
Summary
So this is how we can authenticate the identity of a user by using the Python programming language. Now you can try the same logic with more usernames and other data structures also. I hope you liked this article on how to create a password authentication system using Python. Feel free to ask your valuable questions in the comments section below.