def validate(self): # Check that we have all the required details... # return 1 for OK and 0 for Error state # Now make sure the password isn't too dumb new_password = self.n1password_entry.get() if (new_password != self.n2password_entry.get()): tk.messagebox.showerror( "Memory Error", "Nope. You haven't entered the password the same way twice.\n\nTry again..." ) return 0 if (new_password.lower() in [ "password", "12345678", "qwertyui", "asdfghjk", "zxcvbnm", "87654321", "poiuytre", "lkjhgfds", ",mnbvcxz", "1qaz2wsx", "princess", "iloveyou", "abcd1234", "1234abcd" ]): tk.messagebox.showerror( "Bad Idea Error", "Nope. You chose a really dumb password.\n\nTry again...") return 0 if (new_password.lower() == self.user_entry.lower()): tk.messagebox.showerror( "Bad Idea Error", "Nope. You can't use your Nickname as your password.\n\nTry again..." ) return 0 if (len(new_password) < 8): tk.messagebox.showerror( "Lazybones Error", "Nope. You must have at least 8 characters in your password.\n\nTry again..." ) return 0 nickname = self.user_entry.get() if (' ' in nickname): tk.messagebox.showerror( "Too Creative Error", "Nope. It's a bad idea to have spaces in your Nickname.\n\nTry again..." ) return 0 if (len(nickname) < 4): tk.messagebox.showerror( "Weenie Error", "Your Nickname must be at least 4 characters!\n\nTry again...") return 0 if (db.GetUser(nickname) != None): tk.messagebox.showerror( "Too Popular Error", "Nope. That Nickname is already registered!\n\nHave you already got an account?\n\nYou need to choose a unique Nickname..." ) return 0 if (self.first_entry.get() == "" or self.last_entry.get() == ""): tk.messagebox.showerror( "Shyness Error", "Don't be shy. Please provide both your (real) First and Last names.\n\nTry again..." ) return 0 if (self.first_entry.get().lower() == "first" or self.last_entry.get().lower() == "last"): tk.messagebox.showerror( "Shyness Error", "Ha Ha.\n\nDon't be shy. Please provide both your (real) First and Last names.\n\nTry again..." ) return 0 try: DOB = datetime.datetime.strptime(self.DOB_entry.get(), '%d/%m/%Y') except ValueError: tk.messagebox.showerror( "Odd One Error", "It doesn't look like your DOB is in the right format.\n\nPlease use DD/MM/YYYY..." ) return 0 today = datetime.date.today() age = today.year - DOB.year - ((today.month, today.day) < (DOB.month, DOB.day)) if (age < 6): tk.messagebox.showerror( "Odd One Error", "You seem a little young...is your DOB in the right format?\n\nPlease use DD/MM/YYYY..." ) return 0 if (age > 100): tk.messagebox.showerror( "Odd One Error", "You seem a little old...is your DOB in the right format?\n\nPlease use DD/MM/YYYY..." ) return 0 # Contact number only needed if under 18 if (age < 18): number = self.contact_entry.get() count = sum(c.isdigit() for c in number) if (count == 0): tk.messagebox.showerror( "Phone Home Error", "As you're under 18 we need a guardian's contact number...\n\nPlease provide a valid number." ) return 0 if (count < 10): tk.messagebox.showerror( "Phone Home Error", "It doesn't look like there are enough digits in the contact number mate...\n\nDid you enter the right one?" ) return 0 count = sum(c.isalpha() for c in number) if (count > 0): tk.messagebox.showerror( "Phone Home Error", "Hey! What kind of screwy number has letters in it?\n\nDid you enter the right contact number?" ) return 0 if (number[0] != '0'): tk.messagebox.showerror( "Phone Home Error", "Hey! Doesn't your phone number start with a '0'?\n\nDid you enter the right contact number?" ) return 0 return 1
def apply(self): # We're good to go (Validate will already have been completed) user = db.GetUser(self.user_entry.get()) db.SetPassword(user['UserID'], self.n1password_entry.get()) tk.messagebox.showinfo( "Success!", "Your password has been changed. Don't forget it!")
def Logout(self, parent=None): # We have a dictionary of the member (nicknames) and a flag for the check-box # If we have any 'ticks' we will assume we are performing a 'mentor logout' of one or more members # Mentor has to provide their username/password then all 'ticked' users will be logged out locount = 0 incount = 0 for member, flag in self.registerlist.indojo.items(): incount += 1 if (flag.get()): locount += 1 if (locount >= 1): if(tk.messagebox.askyesno("Mentor Logout", "You have select " + str(locount) + \ " users to logout.\n\nYou need to be a mentor to do this.\n\nProceed?\n\n" + \ " (Did you know there's a new feature that logs out all users without all that tedious ticking as well?)")): doit = MentorPasswordDialog(root, "Mentor Multi-Logout", None).result if (doit == 1): # OK - log them all out for member, flag in self.registerlist.indojo.items(): if (flag.get()): mysqldb.Logout(member) self.LoadRegister() return return name = self.login.nickname_entry.get() password = self.login.password_entry.get() if (name == "" or password == ""): tk.messagebox.showerror( "Shnazbot Error", "Am I supposed to guess who you are?\n\nPerhaps you expect me to smell you?\n\nIt *really* helps if you provide a Nickname AND a Password...\n\nTry again..." ) return # See if this nickname is valid before we check password self.user = mysqldb.GetUser(name) if (self.user == None): tk.messagebox.showerror( "Ponderous Error", "We don't have a record of that Nickname...\n\nLook in the list for your Nickname..." ) return if (not pw.CheckPassword(self.user['Hash'], password)): if (not pw.CheckOldPassword(self.user['Password'], password)): tk.messagebox.showerror( "Memslip Error", "Nope. That's not the password used with this Nickname.\n\nTry again hacker..." ) return # OK - we have a valid login attempt - but are we already logged out? register = mysqldb.GetRegister(self.dojoid, self.user['UserID']) if (register == None or not register['Logout'] == None): if (tk.messagebox.askyesno( "Login?", "You're already logged OUT! Do you want to log in again?") ): self.Login() return # If a mentor logs out we will offer an option to log out everyone else at the same time # even if no others selected - saves tedious selection... if (mysqldb.GetMentor(name, password) != None and incount > 1): if (tk.messagebox.askyesno( "Group Logout", "Hey Mentor - do you want to log out the other " + str(incount - 1) + " users at the same time?")): for member, flag in self.registerlist.indojo.items(): mysqldb.Logout(member) self.LoadRegister() return # We can now log out, update the list and counts. # Easiest way is to update register and then re-load the whole list mysqldb.Logout(self.user['UserID']) self.incount -= 1 self.outcount += 1 self.UpdateStatus() tk.messagebox.showinfo("See Ya!", "You are now logged out\n\nCome back soon!") self.ClearDetails() self.LoadRegister()
def validate(self): # Check that current password matches that already stored and that the two new passwords are identical # return 1 for OK and 0 for Error state # If we have a valid mentor nickname and password then allow password reset without existing password mentorreset = (self.mentor_entry.get() != "" and self.mpassword_entry.get() != "") if (mentorreset): mentor = db.GetMentor(self.mentor_entry.get(), self.mpassword_entry.get()) if (mentor == None): tk.messagebox.showerror( "Mentor Error", "Mentor details aren't right mate...\n\nIf you are trying to reset a password you\nneed a valid Mentor Nickname and Password" ) mentorreset = False nickname = self.user_entry.get() user = db.GetUser(nickname) if (user == None): tk.messagebox.showerror( "Identi Error", "Can't find your details mate...\n\nDid you enter the right Nickname?" ) return 0 if (not mentorreset and not pw.CheckPassword( user['Password'], self.epassword_entry.get())): tk.messagebox.showerror( "Memslip Error", "Nope. You haven't entered the password used with this Nickname.\n\nTry again hacker..." ) return 0 # So we have the right Nickname and the current password # Now make sure the password isn't too dumb new_password = self.n1password_entry.get() if (new_password != self.n2password_entry.get()): tk.messagebox.showerror( "Memory Error", "Nope. You haven't entered the new password the same way twice.\n\nTry again..." ) return 0 if (new_password.lower() in ["password", "12345678", "qwertyui", "asdfghjk", "zxcvbnm"]): tk.messagebox.showerror( "Bad Idea Error", "Nope. You chose a really dumb password.\n\nTry again...") return 0 if (new_password.lower() == nickname.lower()): tk.messagebox.showerror( "Bad Idea Error", "Nope. You can't use your Nickname as your password.\n\nTry again..." ) return 0 #if( new_password.lower() == new_password ): # tk.messagebox.showerror("Lazybones Error", "Nope. You must have at least one UPPERCASE letters in your password.\n\nTry again...") # return 0 if (len(new_password) < 8): tk.messagebox.showerror( "Lazybones Error", "Nope. You must have at least 8 characters in your password.\n\nTry again..." ) return 0 return 1
def Login(self, parent=None, nname=None, npassword=None): if (nname == None and npassword == None): name = self.login.nickname_entry.get() password = self.login.password_entry.get() else: name = nname password = npassword if (name == "" or password == ""): tk.messagebox.showerror( "Doofus Error", "It *really* helps if you provide a Nickname AND a Password...\n\nTry again..." ) return # See if this nickname is valid before we check password self.user = mysqldb.GetUser(name) if (self.user == None): tk.messagebox.showerror( "Ponderous Error", "We don't have a record of that Nickname...\n\nDo you need to register as a New User?" ) return # First check the new password - if not found then check the old one # If the old one is found and it matches then generate a new hash for next time if (not pw.CheckPassword(self.user['Hash'], password)): # We don't have the new style password - so check old if (not pw.CheckOldPassword(self.user['Password'], password)): tk.messagebox.showerror( "Memslip Error", "Nope. That's not the password used with this Nickname.\n\nTry again hacker..." ) return # Old style password OK - so create new hash for next time mysqldb.SetPassword(self.user['UserID'], password) # OK - we have a valid login attempt - but are we already logged in? # If so then ask if we want to logout register = mysqldb.GetRegister(self.dojoid, self.user['UserID']) if (not register == None and register['Logout'] == None): if (tk.messagebox.askyesno( "Logout?", "You're already logged-in. Do you want to logout now?")): self.Logout() return # Finally - show the disclaimer if (not self.disclaimer.ShowDisclaimer()): tk.messagebox.showerror( "Nocompliance Error", "Doh! - You have to accept the disclaimer to log in (and stay at the Dojo).\n\nTry again..." ) return # Now check that we have a contact number for people under 18 - show last one recorded - update if changed needcontact, contactnumber = mysqldb.GetContactNumber( self.user['UserID']) if (needcontact): ChangePhoneDialog(root, title="Check Your Contact Number", user=self.user, number=contactnumber) # add to register, the list and increase login count mysqldb.Login(self.user['UserID']) self.LoadRegister() # Update the Register List if (self.user['LastSeen'] != None): tk.messagebox.showinfo( "Welcome Back " + self.user['FirstName'] + "!", "Hi " + self.user['FirstName'] + ", you are now logged in.\n\nYou last logged in at: " + self.user['LastSeen'].strftime('%H:%M on %a %d-%b-%y') + "\n\nWelcome back!") else: tk.messagebox.showinfo( "Welcome " + self.user['FirstName'] + "!", "Hi " + self.user['FirstName'] + ", you are now logged in.\n\nHope you enjoy the dojo.") # Give Fred a special welcome 'fredjellis' = 17 #if self.user['UserID'] == 17: # self.WelcomeFred() self.ClearDetails()