Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

Python 

My Python Password Generator

I have been learning python and devised this simple project to get used to file operations and random and other Python stuff.
Probably not anything special, but this is a password generator I wrote in Python. The passwords generated are 15 characters long, and according to the M$ website are strong.

Code
import random
import sys
import os.path
from time import time
from base64 import b64encode
def makeKey():
    rnd = random
    rnd.seed(time())
    rand = int(rnd.getrandbits(65535))
    rnd.seed(rand)
    rand = int(rnd.getrandbits(32))
    key = str(rand)
    key = b64encode(key)
    key = list(key)
    key = key[:-2]
    key = key[1:9]
    finalkey = ''.join(key[:])
    finalkey = finalkey + str(rand)
    finalkey = list(finalkey)
    finalkey = finalkey[0:15]
    finalkey = ''.join(finalkey[:])
    return finalkey
madestream = bool(False)
fail = str(None)
keysout = int(255)
print "This could take upto or over a few minutes."
raw_input("Press RETURN to create keys. \n\n")
while keysout >= 0:
       if madestream == False :
            text_file = open("pygenned_keys.txt", "w")
            madestream = True
       else :
           text_file.write(makeKey() + "\n")
           keysout -= 1

if keysout < 0:
    text_file.close()
print "256 Keys created in file 'pygenned_keys.txt'"
print "Key generator by QnTnBlR. \n"
raw_input("Press RETURN to exit!")

Hope you find it useful! 😁

If you like it, please feel free to reply :D


Here is a quick sample of the passwords it generates.

Code
TE0MjYyM1142620
zkwNjcwO3906708
jgxNzA2M2817061
TA5Njg5N9096896
DEyNzExM4127110
jM2NzM3N2367376
TY5NzA5M1697090
TIzNjAwM1236000
jU1NDIzN2554234
TExMDc2M1110760
jE5MjY2N2192667
DAwNDcwO4004709
jE0NDI4M2144281
Not to knock your work but that password would be cracked fast. I mean it is good that you got the caps and lower case and numbers but you forgot special charters $@%^& etc.
(Aug 20, 2010 04:23 PM)Live2Code Wrote:  Not to knock your work but that password would be cracked fast. I mean it is good that you got the caps and lower case and numbers but you forgot special charters $@%^& etc.

I was thinking that, but I didn't think it would ever really get used, so I didn't add that, but it was mainly an exercise to get used to the python built in libraries. I might develop it further, but I don't really think there is much of a need for it. Thanks for the advice :)

EDIT: Changed my mind, I am going to continue to develop it now, I don't really have much on. I will take your advice into consideration, I have thought of a method to do this. Thanks again.
http://www.pastie.org/1105145

This is my version of a password generator I coded few months ago. After learning Python for 2 weeks or something, I still used functions for everything, the program could be better. Your version is good enough for a beginner, so is mine.
Finished off this version, It now generates passwords that are "BEST" on the MS website. Here are some examples of generated keys. I doubled the length.
Code
7Mc3OTD3!Tz34^NzD2Q3EN*Mz0cNg%
3O$MTgw32AIMzzN3#MzA?MM2MDjwgO
N3M42jMDI#3N?0DM4NxODD/~M0Y4gI&
2T6&7N?3N61MN5j4Azjx?DQNx%IxMN

Here is the Python Code.

Code
import random
import sys
import os.path
from time import time
from base64 import b64encode
specialchars = ['!', '?', '$', '%', '^', '*', '&', '#', '/' '~']
def makeKey():
    rnd = random
    rnd.seed(time())
    rand = int(rnd.getrandbits(65535))
    rnd.seed(rand)
    rand = int(rnd.getrandbits(32))
    key = str(rand)
    key = b64encode(key)
    key = list(key)
    key = key[:-2]
    finalkey = ''.join(key[:])
    finalkey = finalkey + str(rand)
    finalkey = list(finalkey)
    finalkey = finalkey[0:15]
    rnd.shuffle(specialchars)
    finalkey[len(finalkey):] = specialchars[0:2]
    rnd.shuffle(finalkey)
    finalkey = finalkey[0:15]
    finalkey = ''.join(finalkey[:])
    return finalkey

madestream = bool(False)
fail = str(None)
keysout = int(255)
print "This could take upto or over a few minutes."
raw_input("Press RETURN to create keys. \n\n")
while keysout >= 0:
  if madestream == False :
    text_file = open("pygenned_keys.txt", "w")
    madestream = True
  else :
  text_file.write(makeKey() + makeKey() + "\n")
  keysout -= 1

if keysout < 0:
    text_file.close()
print "256 Keys created in file 'pygenned_keys.txt'"
print "Key generator by qntnblr. \n"
raw_input("Press RETURN to exit!")


(Aug 20, 2010 04:38 PM)S_C_A_R Wrote:  http://www.pastie.org/1105145

This is my version of a password generator I coded few months ago. After learning Python for 2 weeks or something, I still used functions for everything, the program could be better. Your version is good enough for a beginner, so is mine.

Nice, that is a pretty cool way of generating it, I would imagine that is more efficient than mine.

EDIT: I started python 2 days ago. I used this really good eBook, only about a quarter of the way through it.
Code
import random
import sys
import os.path
from time import time
from base64 import b64encode
specialchars = ['!', '?', '$', '%', '^', '*', '&', '#', '/' '~']
def makeKey():
    rnd = random
    rnd.seed(time())
    rand = int(rnd.getrandbits(65535))
    rnd.seed(rand)
    rand = int(rnd.getrandbits(32))
    key = str(rand)
    key = b64encode(key)
    key = list(key)
    key = key[:-2]
    finalkey = ''.join(key[:])
    finalkey = finalkey + str(rand)
    finalkey = list(finalkey)
    finalkey = finalkey[0:15]
    rnd.shuffle(specialchars)
    finalkey[len(finalkey):] = specialchars[0:2]
    rnd.shuffle(finalkey)
    finalkey = finalkey[0:15]
    finalkey = ''.join(finalkey[:])
    return finalkey

madestream = bool(False)
fail = str(None)
keyx = str()
keysout = int()
keysout = input("Generate how many keys? ")
if (0 >= keysout) :
    print "Invalid number of keys, using 256"
    keysout = 256
keylen = int()
keylen = input("Choose keylength [1-30] : ")
if (1 >= keylen >= 30) :
    print "Invalid Keylength, using 15"
    keylen = 15
keys2 = 0
keys2 += keysout

fname = str
fname = raw_input("Choos a file to write to : ")

print "This could take upto or over a few minutes."
raw_input("Press RETURN to create keys. \n")
while keysout >= 0:
  if madestream == False :
    text_file = open(fname, "w")
    madestream = True
  else :
     keyx = makeKey() + makeKey()
     keyx = keyx[0:keylen]
     text_file.write(keyx + "\n")
     keysout -= 1

if keysout < 0:
    text_file.close()
print str(keys2) + " Keys created in file " + fname
print "Key generator by qntnblr. \n"
raw_input("Press RETURN to exit!")

Alright, completely finished it, and don't worry about me posting more worthless shit on the same thread anymore :)
Code
import random, sys
for i in range(int(raw_input("length: "))): sys.stdout.write("abcdefghijklmnopqrstuvwxyz1234567890"[random.randint(1,35)])
(Aug 21, 2010 02:57 AM)SB91 Wrote:  
Code
sys.stdout.write("abcdefghijklmnopqrstuvwxyz1234567890"[random.randint(1,35)])

That is ingenious, so If I used that, I could change the literal string, and change the count in the randint parameters?
(Aug 21, 2010 03:59 AM)qntnblr Wrote:  That is ingenious, so If I used that, I could change the literal string, and change the count in the randint parameters?

yes and the upper limit has to be 1 less than the length of the string.
(Aug 21, 2010 11:34 AM)SB91 Wrote:  yes and the upper limit has to be 1 less than the length of the string.

Yeah.

If I use this do you want credit?
(Aug 22, 2010 07:07 AM)qntnblr Wrote:  Yeah.

If I use this do you want credit?

you can't really give credit for 1 line of code lol
(Aug 22, 2010 10:26 AM)SB91 Wrote:  you can't really give credit for 1 line of code lol

Fair enough. :)

Thanks for the help :)
Final Version :

http://qntnblr.#/QB_APG.py

Try it out. I'm not gonna post any more password generators.
(Aug 23, 2010 01:42 PM)qntnblr Wrote:  Final Version :

http://qntnblr.spam.com/QB_APG.py

Try it out. I'm not gonna post any more password generators.

That link doesn't work >.< If you could give a working one, I would seriously use this all the time :D
(Aug 24, 2010 04:16 PM)Deadpool™ Wrote:  That link doesn't work >.< If you could give a working one, I would seriously use this all the time :D

That sounded sarcastic...

I'm afraid the only working one I have is sharecash atm.
s h a r e c a s h .org/download.php?file=1176587

... and even if it wasn't, I seriously doubt you would use it more than once to be honest.

edit - Oh, I see what's happened, It keeps getting censored. Check my sig, there is a DL there.


Possibly Related Threads...
Thread / Author Replies Views Last Post
[Python] by Bass_ReevesAug 20, 2023 01:44 AM 9 632 Aug 20, 2023 01:44 AM
Last Post: Lucky4L
[Python] by DarkTitanJul 27, 2020 12:33 PM 0 118 Jul 27, 2020 12:33 PM
Last Post: DarkTitan
[Python] by DipDuo™Mar 29, 2016 07:35 PM 8 355 Mar 29, 2016 07:35 PM
Last Post: DipDuo™