Password Generator

Thread Solved

Join Date: Oct 2009
Posts: 21
Reputation: nevets04 is an unknown quantity at this point 
Solved Threads: 0
nevets04 nevets04 is offline Offline
Newbie Poster

Password Generator

 
0
  #1
16 Days Ago
I know Remembering secure passwords is difficult. So I made this.
  1. import random, os
  2. a= ['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z','1','2','3','4','5','6','7','8','9','{',':','>','?','}','|','!','@','#','$','%','^','&','*','(',')','-','+']
  3.  
  4. z = int(raw_input("How many words in your password?: "))
  5. os.system("clear")
  6. List = []
  7. for x in xrange(z):
  8. List.append(random.choice(a))
  9. print "".join(List)
  10. print "1) Yes"
  11. print "2) No"
  12. b = int(raw_input("Would you like to save this password to a text file?: "))
  13. if b == 1:
  14. c = raw_input("What is this password for?: ")
  15. x = open("%s.txt" % c, "w")
  16. y = "".join(List)
  17. x.write(y)
  18. x.close
  19. x = open("%s.txt" % c, "r")
  20. x.read
  21. print "Saved!"
  22. elif b == 2:
  23. raw_input("Press Enter To Continue")
Reply With Quote Quick reply to this message  
Join Date: Nov 2009
Posts: 22
Reputation: ShadyTyrant is an unknown quantity at this point 
Solved Threads: 5
ShadyTyrant's Avatar
ShadyTyrant ShadyTyrant is offline Offline
Newbie Poster
 
0
  #2
16 Days Ago
I created a Random Password Generator awhile back as well. Mine how ever has a GUI. You can find the complete program at CoderProfile.
  1. #!/usr/bin/env python
  2.  
  3. #----------------------------------------------------------------------
  4. # randompass.py
  5. # Author: Shady Tyrant
  6. # 07/20/2009
  7. #----------------------------------------------------------------------
  8.  
  9. import sys
  10. import random
  11. from GladeWindow import *
  12.  
  13. #----------------------------------------------------------------------
  14.  
  15. class randompass(GladeWindow):
  16.  
  17. #----------------------------------------------------------------------
  18.  
  19. def __init__(self):
  20.  
  21. ''' '''
  22.  
  23. self.init()
  24.  
  25. #----------------------------------------------------------------------
  26.  
  27. def init(self):
  28.  
  29. filename = 'randompass.glade'
  30.  
  31. widget_list = [
  32. 'window1',
  33. 'charNumEntry',
  34. 'genButton',
  35. 'clearButton',
  36. 'passEntry',
  37. ]
  38.  
  39. handlers = [
  40. 'on_genButton_clicked',
  41. 'on_clearButton_clicked',
  42. ]
  43.  
  44. top_window = 'window1'
  45. GladeWindow.__init__(self, filename, top_window, widget_list, handlers)
  46. #----------------------------------------------------------------------
  47.  
  48. def on_genButton_clicked(self, *args):
  49. # Creates tuple of chars used, 71 total
  50. mystring = ("A","B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", \
  51. "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", \
  52. "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", \
  53. "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", \
  54. "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "!", "@", "#", \
  55. "$", "%", "^", "&", "*", "_")
  56.  
  57. try:
  58. num = int(self.widgets['charNumEntry'].get_text())
  59. if num >= 72:
  60. self.widgets['passEntry'].set_text('ERROR: length to large')
  61. except:
  62. self.widgets['passEntry'].set_text('ERROR: Failed Recieving Length Value')
  63.  
  64. # Creates random pass and prints to textbox
  65. rPass = ''.join(random.sample(mystring, num))
  66. self.widgets['passEntry'].set_text(rPass)
  67.  
  68. #----------------------------------------------------------------------
  69.  
  70. def on_clearButton_clicked(self, *args):
  71. self.widgets['passEntry'].set_text('')
  72. self.widgets['charNumEntry'].set_text('')
  73.  
  74. #----------------------------------------------------------------------
  75.  
  76. def main(argv):
  77.  
  78. w = randompass()
  79. w.show()
  80. gtk.main()
  81.  
  82. #----------------------------------------------------------------------
  83.  
  84. if __name__ == '__main__': main(sys.argv)
Reply With Quote Quick reply to this message  
Join Date: Oct 2004
Posts: 3,949
Reputation: vegaseat is just really nice vegaseat is just really nice vegaseat is just really nice vegaseat is just really nice vegaseat is just really nice 
Solved Threads: 915
Moderator
vegaseat's Avatar
vegaseat vegaseat is online now Online
DaniWeb's Hypocrite
 
0
  #3
16 Days Ago
Originally Posted by nevets04 View Post
I know Remembering secure passwords is difficult. So I made this.
  1. import random, os
  2. a= ['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z','1','2','3','4','5','6','7','8','9','{',':','>','?','}','|','!','@','#','$','%','^','&','*','(',')','-','+']
  3.  
  4. z = int(raw_input("How many words in your password?: "))
  5. os.system("clear")
  6. List = []
  7. for x in xrange(z):
  8. List.append(random.choice(a))
  9. print "".join(List)
  10. print "1) Yes"
  11. print "2) No"
  12. b = int(raw_input("Would you like to save this password to a text file?: "))
  13. if b == 1:
  14. c = raw_input("What is this password for?: ")
  15. x = open("%s.txt" % c, "w")
  16. y = "".join(List)
  17. x.write(y)
  18. x.close
  19. x = open("%s.txt" % c, "r")
  20. x.read
  21. print "Saved!"
  22. elif b == 2:
  23. raw_input("Press Enter To Continue")
Nice effort!

My comment, I see you are still using tabs for indentations. Avoid them and use 4 spaces as most other folks. If you use tabs, you sooner or later will mix them with spaces, then your code becomes a mess. Also, if you want to use the 2to3.py utility to convert your code for Python3 later on, it will kick you!

Also avoid os.system("clear"), it is simply not needed and is not at all portable to other systems.
Last edited by vegaseat; 16 Days Ago at 11:02 am.
May 'the Google' be with you!
Reply With Quote Quick reply to this message  
Join Date: Sep 2009
Posts: 104
Reputation: AutoPython is an unknown quantity at this point 
Solved Threads: 9
AutoPython's Avatar
AutoPython AutoPython is offline Offline
Junior Poster
 
1
  #4
16 Days Ago
Instead of manually writing out all the letters and digits do this:

  1. import string
  2. a = list(string.ascii_letters + string.digits + "!@#$%^&*()-+={}|\/?><,.'")
To P(ython), or not to P(ython)
Reply With Quote Quick reply to this message  
Join Date: Nov 2009
Posts: 22
Reputation: ShadyTyrant is an unknown quantity at this point 
Solved Threads: 5
ShadyTyrant's Avatar
ShadyTyrant ShadyTyrant is offline Offline
Newbie Poster
 
0
  #5
16 Days Ago
Originally Posted by AutoPython View Post
Instead of manually writing out all the letters and digits do this:

  1. import string
  2. a = list(string.ascii_letters + string.digits + "!@#$%^&*()-+={}|\/?><,.'")
Oh thats a neat piece of code. I didn't know you could do that.
Reply With Quote Quick reply to this message  
Join Date: Sep 2009
Posts: 104
Reputation: AutoPython is an unknown quantity at this point 
Solved Threads: 9
AutoPython's Avatar
AutoPython AutoPython is offline Offline
Junior Poster
 
1
  #6
15 Days Ago
I actually learned that when I was making a random Password Generator myself .
BTW, That piece of code includes uppercase and lowercase letters. If you want just lower case letters you can use "string.ascii_lowercase" instead of "string.ascii_letters", or if you want all uppercase letters you can do "string.ascii_uppercase".
Last edited by AutoPython; 15 Days Ago at 2:02 pm.
To P(ython), or not to P(ython)
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 2,275
Reputation: sneekula has a spectacular aura about sneekula has a spectacular aura about 
Solved Threads: 175
sneekula's Avatar
sneekula sneekula is offline Offline
Nearly a Posting Maven
 
0
  #7
15 Days Ago
Also the OP didn't want a zero in the digits part.
No one died when Clinton lied.
Reply With Quote Quick reply to this message  
Join Date: Sep 2009
Posts: 104
Reputation: AutoPython is an unknown quantity at this point 
Solved Threads: 9
AutoPython's Avatar
AutoPython AutoPython is offline Offline
Junior Poster
 
0
  #8
15 Days Ago
Okay, instead use:

  1. import string
  2. digits = "".join([loop for loop in range(1, 10)])
  3. a = list(string.ascii_letters + digits + "!@#$%^&*()-+={}|\/?><,.'")
Last edited by AutoPython; 15 Days Ago at 3:19 pm.
To P(ython), or not to P(ython)
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 2,275
Reputation: sneekula has a spectacular aura about sneekula has a spectacular aura about 
Solved Threads: 175
sneekula's Avatar
sneekula sneekula is offline Offline
Nearly a Posting Maven
 
0
  #9
15 Days Ago
Okay, this might even be mildly better:
  1. import string
  2. a = list(string.ascii_lowercase + "!@#$%^&*()-+={}|\/?><,.'") + range(1, 10)
  3.  
  4. print a
For Python3 change to list(range(1, 10)). Oh, the joys of Python!
Last edited by sneekula; 15 Days Ago at 3:53 pm.
No one died when Clinton lied.
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
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