0% found this document useful (0 votes)
23 views

practical10

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views

practical10

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

Create a CSV file by entering user-id and password, read and search the password for given userid.

# importing csv file


import csv
# creating a list to add record
users=[]

# define function to add user


def add_user():
# Taking input username and password
un=input("Enter Username:")
pwd=input("Enter Password:")
# Creating csv file and opening csv file in writing mode
f=open("user.csv","a",newline='')
# Creating writer object
w=csv.writer(f)
# Creating a row with username and password
w.writerow([un,pwd])
# Closing the file
f.close()
print("User added...")

# Defining a seach function


def search():
# Open a file to search password
f=open("user.csv","r")
# Reading data from csv file
r=csv.reader(f)
# Enter username to search password
un=input("Enter Username to search:")
# Traversing through records
for i in r:
# Verifying usernames and displaying password

if i[0]==un:
print("Your password for ", i[0], " is:",i[1])
f.close()

# Creating main menu


while True:
print('''
1. Add user
2. Search Password
3. Exit
''')
ch=int(input("Enter Your Choice:"))
if ch==1:
add_user()
elif ch==2:
search()
elif ch==3:
break
else:
print("Invalid Choice")

1. Add user
2. Search Password
3. Exit

User added...

1. Add user
2. Search Password
3. Exit

Your password for simran is: simran

1. Add user
2. Search Password
3. Exit

Loading [MathJax]/jax/output/CommonHTML/fonts/TeX/fontdata.js

You might also like