Password Storage System.

Reply

Join Date: Mar 2008
Posts: 2
Reputation: sam210 is an unknown quantity at this point 
Solved Threads: 0
sam210 sam210 is offline Offline
Newbie Poster

Password Storage System.

 
0
  #1
Mar 27th, 2008
Okay, so I am creating a password storage system. I have everything but a few last functions.
I need to be able to search for different sites and view all sites in a choicebox. for editting. I've tried a few different things but I just can't get it. the first set of code is the actual coding, and the second set is the simpleDB.py program that I'm using with it.

Thanks for any help.
Samantha
  1. # Password Storage System
  2. ###########################################################
  3.  
  4. from easygui import *
  5. from simpleDB import *
  6.  
  7.  
  8. ############ LIBRARY SECTION - DO NOT EDIT ########################
  9. ## create a new user account
  10. def createLogin():
  11. #prompt for new account information
  12. while 1:
  13. inputs = multpasswordbox("Please Choose", "ID Manager", ["Login ID", "Login Password"])
  14. if len(inputs[0]) < 8 or len(inputs[1]) < 8: #too short id or password
  15. msgbox("UserID and password must be at least 8 characters long." +
  16. "Password must contain at least" +
  17. "1 digit, 1 upper-case letter and 1 lower-case letter")
  18. continue #repeat the prompt
  19. if inputs[0] == inputs[1] : #id and password can't be the same
  20. msgbox("UserID and password should not be the same")
  21. continue #repeat the prompt
  22.  
  23. digit = 0
  24. cap = 0
  25. lower = 0
  26. password = inputs[1]
  27. #validating password format
  28. i = 0
  29. while i < len(password) :
  30. if password[i] >= 'A' and password[i] <= 'Z':
  31. cap = cap + 1
  32. if password[i] >= 'a' and password[i] <= 'z':
  33. lower = lower + 1
  34. if password[i] >= '0' and password[i] <= '9':
  35. digit = digit + 1
  36. i = i+ 1 #check the next character
  37. #let's see if we have the password int he right format
  38. if cap > 0 and lower > 0 and digit > 0:
  39. break # right format => stop checking
  40. else:
  41. msgbox("Password must contain at least 1 digit, 1 upper-case letter and 1 lower-case letter")
  42.  
  43. #everything is good, let's reprompt for the login information
  44. i = 3
  45. while i > 0 :
  46. inputs2 = multpasswordbox("Please provide login information again for verification purpose",
  47. "ID Manager", ["User ID", "Password"])
  48. if inputs2[0] == inputs[0] and inputs2[1] == inputs[1] :
  49. break
  50. msgbox("Unmatched login information")
  51. i = i - 1
  52. else: #terminate the loop without executing the break
  53. msgbox("You have repeatedly entered invalid information. Good bye!")
  54. exit(0)
  55.  
  56. #now check with the database to make sure the id is not taken
  57. for user in getUsers():
  58. if user[0] == inputs2[0]:
  59. msgbox(user[0] + ' has been taken. Please choose a different login ID')
  60. return createLogin()
  61.  
  62. # everything is good, return the obtained loginID and login password
  63. return inputs2
  64. ############################## END OF LIBRARY SECTION #############################
  65.  
  66. # print out user object
  67. def printObj(obj):
  68. msgbox( "Login ID:" + obj.get('login ID') +
  69. '\nLogin Password: ' +obj.get('login password') +
  70. '\nName: ' +obj.get('name') +
  71. '\nEmail Address: '+ obj.get('email') +
  72. '\Home Phone: '+ obj.get('home phone') +
  73. '\nWork Phone: '+ obj.get('work phone') +
  74. '\nHome Address: '+ obj.get('home address') +
  75. '\nWork Address: '+ obj.get('work address'), '\nYour Information for Verification')
  76.  
  77.  
  78. #################################################
  79. #====== Main Program ======#
  80. #=== Start putting your codes from here ======#
  81. #################################################
  82.  
  83. #get all pairs of loginID and loginPass into a list
  84. users = getUsers()
  85.  
  86. choice = None #starting with no choice
  87. if len(users) > 0: #there are some user in the database
  88. choice = buttonbox("Please choose", "ID Manager", ["New Account", "Login"])
  89.  
  90. if len(users)<= 0 or choice == "New Account":
  91. while 1:
  92. loginInfo = createLogin() # create an login account
  93. userid = loginInfo[0] # get the entered login ID
  94. password = loginInfo[1] #get the entered login password
  95.  
  96. #create a new user here
  97. newUser = createUser(userid, password)
  98. if newUser:
  99. #prompt for personal information and update the new user with these information
  100. userInfo = multenterbox("Please provide the following information", "ID Manager",
  101. ["Name", "Email", "Work phone", "Home phone",
  102. "Work address", "Home address"] )
  103. newUser.update('name', userInfo[0])
  104. newUser.update('email', userInfo[1])
  105. newUser.update('work phone', userInfo[2])
  106. newUser.update('home phone', userInfo[3])
  107. newUser.update('work address', userInfo[4])
  108. newUser.update('home address', userInfo[5])
  109.  
  110. #display the input for verification
  111. printObj(newUser)
  112.  
  113. # Repeated prompting for EXIT or NEW SITE:
  114. sites =[]
  115. while 1:
  116. choice = buttonbox('Please Choose', 'Adding new Site', ['New Site', 'Exit'])
  117. if choice == 'Exit' :
  118. exitWithSave() #if EXIT: save the data and exit
  119.  
  120. #if NEW SITE: prompts for information and add them (update) into this user
  121. siteInfo = multenterbox('Please enter site information', 'Adding Site',
  122. ['Site Desc','site login','site password'])
  123.  
  124.  
  125. elif choice == "Login":
  126. i = 3
  127. while i > 0: # allow 3 tries
  128. loginInfo = multpasswordbox('Log in', "ID Manager", ["Login ID", "Login Password"])
  129. user = getUserInfo(loginInfo[0])
  130. if user:
  131. if loginInfo[1] == user.get('login password'):
  132. break
  133.  
  134. i = i -1
  135.  
  136. else: #too many invalid attempts
  137. msgbox("\nYou have too many attempts. Goodbye!")
  138. exit(0)
  139.  
  140. # if we get here, the user must have provided us with a valid login information
  141. # ACTION BLOCK
  142. while 1:
  143. storedInfo = buttonbox("Update Information", "ID Manager", ["EDIT", "SEARCH", "VIEW", "EXIT"])# ask if the user want to EDIT, SEARCH, VIEW, or EXIT the stored information
  144. if storedInfo== "EDIT":# if EDIT is chosen:
  145. userInfo = multenterbox("Please Make Any Changes Necessary Below", "ID Manager",["Name", "Password", "Email", "Work phone", "Home phone","Work address", "Home address"],
  146. [user.get('name'), user.get('password'), user.get('email'), user.get('work phone'), user.get('home phone'), user.get('work address'), user.get('home address')])
  147. user.update('name', userInfo[0])
  148. user.update('password', userInfo[1])
  149. user.update('email', userInfo[2])
  150. user.update('work phone', userInfo[3])
  151. user.update('home phone', userInfo[4])
  152. user.update('work address', userInfo[5])
  153. user.update('home address', userInfo[6])
  154. elif storedInfo=="SEARCH": #if search is chosen:
  155. keyword= enterbox('Enter Keyword', 'Search')
  156. sites=user.get('sites')
  157. if keyword in 'sites':
  158. msgbox('please say hello')
  159.  
  160.  
  161. elif storedInfo=="VIEW": #if VIEW is chosen:
  162. if len(sites)>0:
  163. #**********# site id : site password : site description
  164. ##*******#if the user clicks on any of this choice, show the selected site information for editing
  165. print hello
  166. elif storedInfo=="EXIT":
  167. exitWithSave()
  168.  
  169. else: #unhandled cases
  170. exit(0)


AND


  1. import os.path
  2. import pickle
  3. from xml.dom import minidom, Node
  4.  
  5. DATABASE_NAME='db'
  6. DATABASE = None #database root
  7.  
  8. ######################################################
  9. #simple xor encryption to the fisrt character
  10. def __encryptXOR__(text):
  11. #return text
  12. data = []
  13. if len(text) <= 0:
  14. return ''
  15. data.append(text[0])
  16. i = 1
  17. while i < len(text):
  18. e = ord(text[i]) ^ ord(text[0])
  19. data.append(chr(e))
  20. i += 1
  21. return ''.join(data)
  22. #####################################################
  23. #open a file, read its contain and return the content
  24. def __loadFile__(fileName):
  25. lines =[] # a list of all lines
  26. openFile = open(fileName, 'rb')
  27. #read the content into a list
  28. if openFile:
  29. lines = ''.join(openFile.readlines(os.path.getsize(fileName)))
  30. openFile.close() #close the file
  31. return __encryptXOR__(''.join(lines))
  32.  
  33. ######################################################
  34. #save the given string into a file
  35. def __saveFile__(data):
  36. data = __encryptXOR__(data)
  37. if len(data) > 0:
  38. newFile = file(DATABASE_NAME, "w")
  39. newFile.write(data)
  40. newFile.close()
  41. #######################################################
  42. # save the data and exit
  43. def exitWithSave():
  44. __saveFile__(DATABASE.toxml())
  45. exit(0)
  46.  
  47. ####################################################
  48. #indicate if the data file exists
  49. def __databaseExists__(fileName):
  50. return os.path.exists(fileName)
  51.  
  52. ###########################################
  53. #read an xml database and return the root node
  54. def __readDB__(fileName, createNew=0):
  55. global DATABASE
  56. if createNew: #create new database
  57. DATABASE = minidom.parseString("<db></db>")
  58. else:
  59. s = __loadFile__(fileName) #load the data file as a string
  60. DATABASE = minidom.parseString(s)
  61.  
  62. return DATABASE
  63.  
  64. ############################
  65. #class representing a user
  66. class User:
  67. #constructor
  68. def __init__(self, node):
  69. self.__user__ = node
  70.  
  71. #get the data of a given field with tag name
  72. def get(self, tagName):
  73. if tagName == 'sites':
  74. accounts=[]
  75. #retrieve account information
  76. for acct in self.__user__.getElementsByTagName("site"):
  77. desc = __getNodeData__(acct, "desc")
  78. id = __getNodeData__(acct, "id")
  79. passwd = __getNodeData__(acct, "pass")
  80. accounts.append([desc, id, passwd])
  81. return accounts
  82. else: #return the data of the given field
  83. return __getNodeData__(self.__user__, tagName);
  84. # store this user back to the xml dom tree
  85. def update(self, tagName, value):
  86. tagName = __formatTagName__(tagName)
  87. if tagName != 'SITES' and tagName != 'LOGINID': #can't change loginID
  88. #update top level field
  89. __setNodeData__(self.__user__, tagName, value)
  90. else: #update the sites
  91. #drop the sites element
  92. element = self.__user__.getElementsByTagName('SITES')
  93. if element:
  94. self.__user__.removeChild(element[0])
  95. #create a new sites node
  96. sites = __newNode__('sites', '')
  97. for item in value: #scan each site
  98. site = __newNode__('site', '')
  99. site.appendChild(__newNode__("desc", item[0]))
  100. site.appendChild(__newNode__("id", item[1]))
  101. site.appendChild(__newNode__("pass", item[2]))
  102. sites.appendChild(site) #add the site to the list of sites
  103. #add the sites back to the user
  104. self.__user__.appendChild(sites)
  105.  
  106. # print '\nAfter update' + self.__user__.toprettyxml()
  107.  
  108. #######################################################
  109. # format tagname
  110. def __formatTagName__(tagName):
  111. tagName = tagName.upper() #convert to upper case
  112. tagName =tagName.replace(' ','') #remove blank
  113. tagName = tagName.replace('-','')
  114. tagName = tagName.replace('_','')
  115. return tagName
  116.  
  117. #######################################################
  118. def __newNode__(tagName, value):
  119. tagName = __formatTagName__(tagName)
  120. node = DATABASE.createElement(tagName)
  121. node.appendChild(DATABASE.createTextNode(value.strip()))
  122. return node
  123.  
  124. #######################################################
  125. # return whether the given id is in the database
  126. def __uniqueIDExist__(tagName, newID):
  127. tagName = __formatTagName__(tagName)
  128. root= DATABASE
  129. for eID in root.childNodes:
  130. existingID = __getNodeData__(eID, tagName)
  131. # print 'comparing ' + existingID + 'with '+ newID
  132. # raw_input()
  133. if existingID == newID:
  134. return True
  135. return False
  136.  
  137. ##############################################################
  138. #given a node, return its text data
  139. def __getNodeData__(node, tagName):
  140. tagName = __formatTagName__(tagName) #convert to upper case
  141. data = ""
  142. element = node.getElementsByTagName(tagName)
  143. if element: #if exists then extract data
  144. for childNode in element[0].childNodes:
  145. if childNode.nodeType == Node.TEXT_NODE:
  146. data += childNode.data
  147. return data
  148. ##############
  149. #change the value of a node
  150. def __setNodeData__(node, tagName, value):
  151. tagName = __formatTagName__(tagName)
  152. value = value.strip()
  153. element = node.getElementsByTagName(tagName)
  154. if element: #if exist, update it
  155. for childNode in element[0].childNodes:
  156. if childNode.nodeType == Node.TEXT_NODE:
  157. childNode.data = value
  158. break
  159. else: #create a new node
  160. node.appendChild(__newNode__(tagName, value))
  161.  
  162. ###############################################################
  163. ## ===========Starting Database API ============
  164. ###############################################################
  165. #return a list of loginID and loginPass
  166. def getUsers():
  167. info = []
  168. #no database, create a new one and return empty list
  169. if not __databaseExists__(DATABASE_NAME):
  170. __readDB__(DATABASE_NAME, 1)
  171. return info
  172.  
  173. #open database and extract information
  174. __readDB__(DATABASE_NAME)
  175. root= DATABASE
  176. userTag = __formatTagName__('user')
  177.  
  178. for user in root.getElementsByTagName(userTag):
  179. userID = __getNodeData__(user, "loginID")
  180. password = __getNodeData__(user, "loginPassword")
  181. #add these to the list
  182. info.append([userID,password])
  183. return info
  184.  
  185. #############################################
  186. #get all information about a given user
  187. def getUserInfo(userID):
  188. root = DATABASE
  189. #print '\nin get user info ', root.toprettyxml()
  190. tagName = __formatTagName__('user')
  191. for user in root.getElementsByTagName(tagName):
  192. ID = __getNodeData__(user, "loginID")
  193. #found the user, build a user object and return
  194. if userID == ID:
  195. return User(user)
  196.  
  197. #####################
  198. #creating a new user with the given id and password
  199. def createUser(loginID, password):
  200. #make sure there is no duplicate id in the database
  201. if __uniqueIDExist__('loginID', loginID):
  202. #print 'ID: '+ loginID + ' exists'
  203. return None
  204. user = __newNode__("user", '')
  205. user.appendChild(__newNode__('loginID', loginID))
  206. user.appendChild(__newNode__('loginPassword', password))
  207. root = DATABASE.getElementsByTagName("db")[0]
  208. root.appendChild(user) #add the user to the database
  209. return User(user)
Reply With Quote Quick reply to this message  
Join Date: Dec 2006
Posts: 977
Reputation: woooee is a jewel in the rough woooee is a jewel in the rough woooee is a jewel in the rough 
Solved Threads: 273
woooee woooee is offline Offline
Posting Shark

Re: Password Storage System.

 
0
  #2
Mar 27th, 2008
For viewing and editing, try passing data to TableListWrapper, http://tkinter.unpythonic.net/wiki/TableListWrapper The edittest() function is the one to try.
Reply With Quote Quick reply to this message  
Join Date: Mar 2008
Posts: 2
Reputation: sam210 is an unknown quantity at this point 
Solved Threads: 0
sam210 sam210 is offline Offline
Newbie Poster

Re: Password Storage System.

 
0
  #3
Mar 27th, 2008
Thanks, but that's really not what I'm looking for. The project calls for the use of only SimpleDB, easygui, and the program itsself. I want to understand the commands....


but once again, thanks for trying.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the Python Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC