forked from Ananyasingh2002/Hacktoberfest2023
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFile-handling-Auth-Python.py
53 lines (53 loc) · 2.23 KB
/
File-handling-Auth-Python.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import os
print('\nCreate Account : Enter ( Create ) \nTo Login : Enter ( Login ) \nTo Change Password : Enter ( Reset )\n')
data = input("How Can I Help You\n")
if data == 'create':
def data_fun(name,password):
path="path"+name
isFile = os.path.isfile(path)
if isFile is True:
print("\nUser Name Not Available\n")
else:
with open("path"+name,'a') as create:
create.write("User:"+name+" "+"Passwd:"+password)
print("\nAccount Create Successfully\n")
name = input("Enter Your User Name :")
password = input("Enter User Password :")
data_fun(name,password)
elif data == 'login':
def data_fun(name,password):
path="path"+name
isFile = os.path.isfile(path)
if isFile is True:
with open("path"+name,'r') as login:
user=("User:"+name+" "+"Passwd:"+password)
if user == login.readline():
print("\nLogin Successfully\n")
else:
print("\nEntered Credentials are Invalid\n")
name = input("Enter Your User Name :")
password = input("Enter User Password :")
data_fun(name,password)
elif data == 'reset':
def data_name(name,password,newpassword):
with open("path"+name,'r') as reset:
user="User:"+name+" Passwd:"+password
if user in reset.readlines():
content = user
with open("path"+name,'w+') as files:
lines = files.readlines()
for line in lines:
if line.strip("\n") != content:
files.write (line)
c="User:"+name+" Passwd:"+newpassword
with open("path"+name,'a') as reset_new:
reset_new.write(c)
print("\nPassword Changed Successfully\n")
else:
print('\nPlease Enter Correct Credentials\n')
name=input("Enter User Name : ")
password=input("Enter User Password : ")
newpassword=input("Enter New Password : ")
data_name(name,password,newpassword)
else:
print("\nPlease Enter Correct Credentials\n")