login (simple version)
A simple Python login system.
import sys
import csv
loggedin = False
users = csv.csv2sequence('users.csv')
username = input('Enter username : ')
password = input('Enter password : ')
for user in users:
if username == user[0] and password == user[1]:
loggedin = True
break
if loggedin:
print('Success - you are logged in as \'{0}\'.'.format(username))
else:
print('Incorrect username or password.')
sys.exit()
# Rest of program goes here ...
print('This is the rest of the program ...')
I've provided a copy of this Python script, the csv.py library and the users.csv file containing the sample usernames and passwords. Fill your boots.
Last modified: March 20th, 2023