-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
67 additions
and
0 deletions.
There are no files selected for viewing
67 changes: 67 additions & 0 deletions
67
sqlphp/developer-notes/python/core.python/python.login.signup.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
>>>>> Python Login & Sign Up <<<<< | ||
|
||
|
||
---------------------------------------------------------------------------- | ||
---------------------------------------------------------------------------- | ||
---------------------------------------------------------------------------- | ||
|
||
1. basic Login & Sign UP for beginners | ||
https://medium.com/@moinahmedbgbn/a-basic-login-system-with-python-746a64dc88d6 | ||
|
||
---------------------------------------------------------------------------- | ||
---------------------------------------------------------------------------- | ||
---------------------------------------------------------------------------- | ||
---------------------------------------------------------------------------- | ||
|
||
>>> 1. A Basic Login System with Python | ||
|
||
Concept | ||
|
||
The program will accept the user’s email and password, hash the password, store it into a text file with the email, and complete the registration process. | ||
|
||
|
||
Prerequisites | ||
|
||
You should have installed python version 3.0 or above to use the built-in package hashlib. | ||
|
||
|
||
import hashlib | ||
def signup(): | ||
email = input(“Enter email address: “) | ||
pwd = input(“Enter password: “) | ||
conf_pwd = input(“Confirm password: “) if conf_pwd == pwd: | ||
enc = conf_pwd.encode() | ||
hash1 = hashlib.md5(enc).hexdigest() with open(“credentials.txt”, “w”) as f: | ||
f.write(email + “\n”) | ||
f.write(hash1) | ||
f.close() | ||
print(“You have registered successfully!”) else: | ||
print(“Password is not same as above! \n”)def login(): | ||
email = input(“Enter email: “) | ||
pwd = input(“Enter password: “) auth = pwd.encode() | ||
auth_hash = hashlib.md5(auth).hexdigest() | ||
with open(“credentials.txt”, “r”) as f: | ||
stored_email, stored_pwd = f.read().split(“\n”) | ||
f.close() if email == stored_email and auth_hash == stored_pwd: | ||
print(“Logged in Successfully!”) | ||
else: | ||
print(“Login failed! \n”)while 1: | ||
print("********** Login System **********") | ||
print("1.Signup") | ||
print("2.Login") | ||
print("3.Exit") | ||
ch = int(input("Enter your choice: ")) | ||
if ch == 1: | ||
signup() | ||
elif ch == 2: | ||
login() | ||
elif ch == 3: | ||
break | ||
else: | ||
print("Wrong Choice!") | ||
|
||
---------------------------------------------------------------------------- | ||
---------------------------------------------------------------------------- | ||
---------------------------------------------------------------------------- | ||
---------------------------------------------------------------------------- | ||
---------------------------------------------------------------------------- |