| | |
Password Generator
Thread Solved |
•
•
Join Date: Oct 2009
Posts: 21
Reputation:
Solved Threads: 0
I know Remembering secure passwords is difficult. So I made this.
Python Syntax (Toggle Plain Text)
import random, os 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','{',':','>','?','}','|','!','@','#','$','%','^','&','*','(',')','-','+'] z = int(raw_input("How many words in your password?: ")) os.system("clear") List = [] for x in xrange(z): List.append(random.choice(a)) print "".join(List) print "1) Yes" print "2) No" b = int(raw_input("Would you like to save this password to a text file?: ")) if b == 1: c = raw_input("What is this password for?: ") x = open("%s.txt" % c, "w") y = "".join(List) x.write(y) x.close x = open("%s.txt" % c, "r") x.read print "Saved!" elif b == 2: raw_input("Press Enter To Continue")
0
#2 18 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.
Python Syntax (Toggle Plain Text)
#!/usr/bin/env python #---------------------------------------------------------------------- # randompass.py # Author: Shady Tyrant # 07/20/2009 #---------------------------------------------------------------------- import sys import random from GladeWindow import * #---------------------------------------------------------------------- class randompass(GladeWindow): #---------------------------------------------------------------------- def __init__(self): ''' ''' self.init() #---------------------------------------------------------------------- def init(self): filename = 'randompass.glade' widget_list = [ 'window1', 'charNumEntry', 'genButton', 'clearButton', 'passEntry', ] handlers = [ 'on_genButton_clicked', 'on_clearButton_clicked', ] top_window = 'window1' GladeWindow.__init__(self, filename, top_window, widget_list, handlers) #---------------------------------------------------------------------- def on_genButton_clicked(self, *args): # Creates tuple of chars used, 71 total mystring = ("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", \ "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", \ "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "!", "@", "#", \ "$", "%", "^", "&", "*", "_") try: num = int(self.widgets['charNumEntry'].get_text()) if num >= 72: self.widgets['passEntry'].set_text('ERROR: length to large') except: self.widgets['passEntry'].set_text('ERROR: Failed Recieving Length Value') # Creates random pass and prints to textbox rPass = ''.join(random.sample(mystring, num)) self.widgets['passEntry'].set_text(rPass) #---------------------------------------------------------------------- def on_clearButton_clicked(self, *args): self.widgets['passEntry'].set_text('') self.widgets['charNumEntry'].set_text('') #---------------------------------------------------------------------- def main(argv): w = randompass() w.show() gtk.main() #---------------------------------------------------------------------- if __name__ == '__main__': main(sys.argv)
0
#3 18 Days Ago
•
•
•
•
I know Remembering secure passwords is difficult. So I made this.
Python Syntax (Toggle Plain Text)
import random, os 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','{',':','>','?','}','|','!','@','#','$','%','^','&','*','(',')','-','+'] z = int(raw_input("How many words in your password?: ")) os.system("clear") List = [] for x in xrange(z): List.append(random.choice(a)) print "".join(List) print "1) Yes" print "2) No" b = int(raw_input("Would you like to save this password to a text file?: ")) if b == 1: c = raw_input("What is this password for?: ") x = open("%s.txt" % c, "w") y = "".join(List) x.write(y) x.close x = open("%s.txt" % c, "r") x.read print "Saved!" elif b == 2: raw_input("Press Enter To Continue")
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; 18 Days Ago at 11:02 am.
May 'the Google' be with you!
1
#4 18 Days Ago
Instead of manually writing out all the letters and digits do this:
Python Syntax (Toggle Plain Text)
import string a = list(string.ascii_letters + string.digits + "!@#$%^&*()-+={}|\/?><,.'")
To P(ython), or not to P(ython)
0
#5 18 Days Ago
•
•
•
•
Instead of manually writing out all the letters and digits do this:
Python Syntax (Toggle Plain Text)
import string a = list(string.ascii_letters + string.digits + "!@#$%^&*()-+={}|\/?><,.'")
1
#6 18 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".
. 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; 18 Days Ago at 2:02 pm.
To P(ython), or not to P(ython)
0
#8 18 Days Ago
Okay, instead use:
Python Syntax (Toggle Plain Text)
import string digits = "".join([loop for loop in range(1, 10)]) a = list(string.ascii_letters + digits + "!@#$%^&*()-+={}|\/?><,.'")
Last edited by AutoPython; 18 Days Ago at 3:19 pm.
To P(ython), or not to P(ython)
0
#9 18 Days Ago
Okay, this might even be mildly better:
For Python3 change to list(range(1, 10)). Oh, the joys of Python!
Python Syntax (Toggle Plain Text)
import string a = list(string.ascii_lowercase + "!@#$%^&*()-+={}|\/?><,.'") + range(1, 10) print a
Last edited by sneekula; 18 Days Ago at 3:53 pm.
No one died when Clinton lied.
![]() |
Similar Threads
- Password Generator (Java)
- Code Snippet: Quick password generator (Ruby)
- Password Generator (Visual Basic 4 / 5 / 6)
Other Threads in the Python Forum
- Previous Thread: sudoku solver problem
- Next Thread: Cramer's Rule please
| Thread Tools | Search this Thread |
accessdenied advanced apache application argv beginner change command convert csv cursor def dictionary digital dynamic dynamically edit enter event examples file float format frange function google gui homework i/o import inches input jaunty java keyboard lapse library line lines linux list lists loop microphone mouse movingimageswithpygame newb number numbers numeric obexftp output parameters parsing path phonebook port prime programming projects py2exe pygame pygtk pyopengl python random recursion redirect remote return reverse scrolledtext session simple skinning software sprite statictext string strings syntax terminal text threading time tkinter tlapse trick tuple tutorial ubuntu unicode unit urllib urllib2 variable voip web-scrape wordgame wxpython






