ALERT!
Click here to register with a few steps and explore all our cool stuff we have to offer!
Home
Upgrade
Credits
Help
Search
Awards
Achievements
 4121

Password generator

by ronaar - 12-10-2017 - 08:22 PM
#1
import random
import hashlib
from Tkinter import *
import tkMessageBox

def resetBox():
    length.delete(0, END)

def genPassword():
    end = int(length.get())
    i = 1
    password = ''
    while(i <= end):
        choice = int(float(random.uniform(1,12)))
        if choice <= 3:
            #reg char
            password = password + random.choice('abcdefghijklmnopqrstuvwxyz')
            i+=1
        else:
            if choice <= 6:
                #capitalized char
                password = password + random.choice('abcdefghijklmnopqrstuvwxyz').upper()
                i+=1
            else:
                if choice <= 9:
                    #sym
                    password = password + random.choice('~`!@#$%^&*()_-+={}[]|\\:;"\'<,>.?/')
                    i+=1
                else:
                    if choice <= 12:
                        #int
                        password = password + random.choice('0123456789')
                        i+=1
                    else:
                        print ''
    root.clipboard_clear()
    root.clipboard_append(password)
    tkMessageBox.showinfo("Password", "The generated password %s was copied to your clipboard." % password)

root = Tk()
root.title("Secure Password Generator")
root.geometry("350x130")
root.iconbitmap("key.ico")
root.resizable(0,0)

title = Label(root, text="Secure Password Generator", font=("Arial", 18))
title.pack()

frame = Frame(root, relief=SUNKEN, height=2, bd=1)
frame.pack(fill=X, padx=5)

framemid = Frame(root, relief=FLAT, borderwidth=1)
framemid.pack(fill=X, expand=1)

instructions = Label(framemid, text="Password Length: ")
instructions.pack(side='left', padx=15)

length = Entry(framemid, width=30)
length.pack(side='left')

framebottom = Frame(root, relief=SUNKEN, height=2, bd=1)
framebottom.pack(fill=X, padx=5)

reset = Button(root, text="Reset", width=10, padx=1, pady=1, command=resetBox)
reset.pack(side='right', padx=5)
generator = Button(root, text="Generate", width=10, padx=1, pady=1, command=genPassword)
generator.pack(side='right', anchor='s', padx=5, pady=5)

root.mainloop()
Reply
#2
what language for programming??
Reply
#3
Your algorithm for generating passwords isn't very good. you shouldn't do that many string appends it is slow to generate keys.

Instead try:

import random
import string

random.seed() # <!-- Use this line to generate a pseudo random seed and only do this ONCE at the top of the file as a global.

password = "".join(random.choice(string.ascii_lowercase) for x in range(length_of_string)) # <!--  this generates the password string and is much faster and less computationally expensive.

Happy Hacking

Quote:def genPassword():
    end = int(length.get())
    i = 1
    password = ''
    while(i <= end):
        choice = int(float(random.uniform(1,12)))
        if choice <= 3:
            #reg char
            password = password + random.choice('abcdefghijklmnopqrstuvwxyz')
            i+=1
        else:
            if choice <= 6:
                #capitalized char
                password = password + random.choice('abcdefghijklmnopqrstuvwxyz').upper()
                i+=1
            else:
                if choice <= 9:
                    #sym
                    password = password + random.choice('~`!@#$%^&*()_-+={}[]|\\:;"\'<,>.?/')
                    i+=1
                else:
                    if choice <= 12:
                        #int
                        password = password + random.choice('0123456789')
                        i+=1
                    else:
                        print ''



Instead could be:

Quote:import random
import string

random.seed()


def genPassword():
        return "".join(random.choice(string.ascii_letters + string.punctuation) for x in range(int(length.get())))
Reply
#4
Thank you very much will be very useful
Reply
#5
(12-11-2017 - 01:44 AM)SplenderSpend1 Wrote: what language for programming??

Python. You can download it here. The only thing I'm unsure of is what version of python he is using, you'll have to figure that out yourself or ask him.

Nice job but you should really simplify your code.
25% off coupon: DemonForums
Reply
#6
Nice source code, did you write It alone?
Reply

Users browsing: 1 Guest(s)