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
54
55
56
57
58
59
60
61
62
import gspread
from oauth2client.service_account import ServiceAccountCredentials
scope = ['https://spreadsheets.google.com/feeds',
'https://www.googleapis.com/auth/drive']
credentials = ServiceAccountCredentials.from_json_keyfile_name('Python Test-32b5fbe50b83.json', scope)
gc = gspread.authorize(credentials)
wks = gc.open("Test For Python Integration").sheet1
def validatePass(p1, p2):
if p1 == p2:
return True
def next_available_row(worksheet):
str_list = worksheet.col_values(1)
return len(str_list)+1
def createAuth():
global wks
while True:
user = input("Please enter a Username: ")
passW = input("Please enter a Password: ")
passW2 = input("Please confirm your Password: ")
if validatePass(passW, passW2):
try:
wks.find(user)
except:
wks.resize(next_available_row(wks))
wks.append_row([user, passW])
print("Sign up successful. Your data will be saved.")
break
print("Username already exists. Please try again with a different username.")
else:
print("Your passwords didn't match. Please try again.")
def login():
global wks
while 1:
user = input("Please enter your Username: ")
passW = input("Please enter your Password: ")
try:
t1 = wks.find(user)
except:
print("Invalid username. Please try again or create a new account.")
continue
if wks.cell(t1.row, t1.col+1).value == passW:
print("Login successful. Welcome back.")
break
else:
print("Incorrect password")
choice = int(input("1) Sign Up\n2) Login\n> "))
if choice == 1:
createAuth()
else:
login()