Password Generator

Please support our Python advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved

Join Date: Oct 2009
Posts: 26
Reputation: nevets04 is an unknown quantity at this point 
Solved Threads: 1
nevets04 nevets04 is offline Offline
Light Poster

Password Generator

 
0
  #1
Nov 6th, 2009
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: 75
Reputation: ShadyTyrant is an unknown quantity at this point 
Solved Threads: 10
ShadyTyrant's Avatar
ShadyTyrant ShadyTyrant is offline Offline
Junior Poster in Training
 
0
  #2
Nov 7th, 2009
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: 4,161
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: 980
Moderator
vegaseat's Avatar
vegaseat vegaseat is offline Offline
DaniWeb's Hypocrite
 
0
  #3
Nov 7th, 2009
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; Nov 7th, 2009 at 11:02 am.
May 'the Google' be with you!
Reply With Quote Quick reply to this message  
Join Date: Sep 2009
Posts: 112
Reputation: AutoPython is an unknown quantity at this point 
Solved Threads: 14
AutoPython's Avatar
AutoPython AutoPython is offline Offline
Junior Poster
 
1
  #4
Nov 7th, 2009
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: 75
Reputation: ShadyTyrant is an unknown quantity at this point 
Solved Threads: 10
ShadyTyrant's Avatar
ShadyTyrant ShadyTyrant is offline Offline
Junior Poster in Training
 
0
  #5
Nov 7th, 2009
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: 112
Reputation: AutoPython is an unknown quantity at this point 
Solved Threads: 14
AutoPython's Avatar
AutoPython AutoPython is offline Offline
Junior Poster
 
1
  #6
Nov 7th, 2009
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; Nov 7th, 2009 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,305
Reputation: sneekula has a spectacular aura about sneekula has a spectacular aura about 
Solved Threads: 181
sneekula's Avatar
sneekula sneekula is offline Offline
Nearly a Posting Maven
 
0
  #7
Nov 7th, 2009
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: 112
Reputation: AutoPython is an unknown quantity at this point 
Solved Threads: 14
AutoPython's Avatar
AutoPython AutoPython is offline Offline
Junior Poster
 
0
  #8
Nov 7th, 2009
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; Nov 7th, 2009 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,305
Reputation: sneekula has a spectacular aura about sneekula has a spectacular aura about 
Solved Threads: 181
sneekula's Avatar
sneekula sneekula is offline Offline
Nearly a Posting Maven
 
0
  #9
Nov 7th, 2009
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; Nov 7th, 2009 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


Views: 344 | Replies: 8
Thread Tools Search this Thread



Tag cloud for Python
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC