Page 2 of 3 FirstFirst 123 LastLast
Results 11 to 20 of 25

Thread: Quick and easy random password generator

  1. #11
    Join Date
    Jul 2010
    Beans
    1

    Re: Quick and easy random password generator

    There is no need to make a script for password generation. I you this command every time i need some random string.

    http://www.usermadetutorials.com/201...rator-in-bash/

    I've used that command a lot of times - i change a lot of password every day - i work on a company with a lot of email accounts.

  2. #12
    Join Date
    Aug 2006
    Beans
    1

    Re: Quick and easy random password generator

    Hi,

    You can also use:
    http://www.desmoulins.fr/index_us.ph...online!genpass

    which is a "Human readable" online password generator.


    Hoping this will help.

  3. #13
    Join Date
    Apr 2008
    Beans
    41

    Re: Quick and easy random password generator

    Thanks for sharing - I love this little script!

    Though I feel from some of the some of the replies that others do not completely see its use...


    This script not only generates a random password for you but also gives you the ability to quickly recall that password using the master pass:

    Code:
    ~: ./passgen.sh
    Enter the master password
    ubunturox
    
    Enter the reason
    github.com
    
    Enter desired number of characters
    10
    
    Your random password is:
    af95accd4c
    Entering the same details every time will always result in your created password being returned. very neat

  4. #14
    Join Date
    Nov 2009
    Location
    The Netherlands
    Beans
    239
    Distro
    Ubuntu 12.04 Precise Pangolin

    Re: Quick and easy random password generator

    I noticed that this script only generates passwords with lower case letters and digits.
    So i made a different one that generates passwords that also contain upper case letters (and its fairly easy to expand it to also give other characters)
    I'm not very good at bash so it's in python:
    Code:
    #!/usr/bin/env python
    
    import sys, string, hashlib, getpass
    
    ask_silent = getpass.getpass
    
    def ask_normal(str):
        sys.stderr.write(str)
        return sys.stdin.readline()
    
    if '-s' in sys.argv or '--silent' in sys.argv:
        ask_normal = getpass.getpass
    else:
        sys.stderr.write('Warning, by default the reason and password length are not'
        ' read as passwords (your console will show what you type). If you do not '
        ' want this, use the -s or --silent option.\n')
    
    
    mastone = 'x'
    masttwo = 'y'
    while mastone != masttwo:
        mastone = ask_silent("Enter the master password: ")
        masttwo = ask_silent("Retype the master password: ")
        if mastone != masttwo:
            sys.stderr.write("Password entries don't match, try again\n")
    
    reason = ask_normal("Enter the reason: ")
    
    passlength = 'ten'
    while type(passlength) != type(10):
        try:
            passlength = int(ask_normal("Enter desired number of characters: "))
        except ValueError:
            sys.stderr.write("Please enter a number.\n")
    
    characters = string.ascii_letters + string.digits # add other characters that can be used in your passwords here
    
    hash = hashlib.sha256()
    len_to_go = passlength
    pwd = ''
    while len_to_go:
        hash.update(mastone)
        hash.update(reason)
        binary_pass = [ord(c) for c in hash.digest()]
        pwd_part = ''.join([characters[i % len(characters)] for i in binary_pass])[0:len_to_go]
        len_to_go -= len(pwd_part)
        pwd += pwd_part
    
    sys.stderr.write('Your password is:\n')
    sys.stdout.write(pwd + '\n')
    This script can also generate passwords longer than 40 characters.
    Please note that this script is not compatible with previous scripts in this thread.

    btw. This script uses sha256 instead of sha1, but thats easily changed too if you want.

  5. #15
    Join Date
    Apr 2008
    Beans
    41

    Re: Quick and easy random password generator

    very nice!!!

    I really need to learn some Python..... Im really too bash addicted!! LOL!

  6. #16
    Join Date
    Nov 2009
    Location
    The Netherlands
    Beans
    239
    Distro
    Ubuntu 12.04 Precise Pangolin

    Re: Quick and easy random password generator

    I noticed a bug in my previous script, the getpass function removes the newline but sys.stdin.getline() doesn't so the passwords generated with the -s option would be different from the passwords without that option.

    Here is a fixed version:
    Code:
    #!/usr/bin/env python
    
    import sys, string, hashlib, getpass
    
    ask_silent = getpass.getpass
    
    def ask_normal(str):
        sys.stderr.write(str)
        return sys.stdin.readline()[0:-1] # remove the newline
    
    def ask_master():
        mastone = 'x'
        masttwo = 'y'
        while mastone != masttwo:
            mastone = ask_silent("Enter the master password: ")
            masttwo = ask_silent("Retype the master password: ")
            if mastone != masttwo:
                sys.stderr.write("Password entries don't match, try again\n")
        return mastone
    
    def ask_length():
        passlength = 'ten'
        while type(passlength) != type(10):
            try:
                passlength = int(ask_normal("Enter desired number of characters: "))
            except ValueError:
                sys.stderr.write("Please enter a number.\n")
        return passlength
    
    
    def generate(master, reason, length):
        characters = string.ascii_letters + string.digits # add other characters that can be used in your passwords here
        hash = hashlib.sha256()
        len_to_go = length
        pwd = ''
        while len_to_go:
            hash.update(master)
            hash.update(reason)
            binary_pass = [ord(c) for c in hash.digest()]
            pwd_part = ''.join([characters[i % len(characters)] for i in binary_pass])[0:len_to_go]
            len_to_go -= len(pwd_part)
            pwd += pwd_part
        return pwd
    
    def main_console(argv):
        if '-s' in argv or '--silent' in argv:
            global ask_normal
            ask_normal = getpass.getpass
        else:
            sys.stderr.write('Warning, by default the reason and password length are not'
            ' read as passwords (your console will show what you type). If you do not '
            ' want this, use the -s or --silent option.\n')
    
        if '-u' in argv or '--unsafe' in argv:
            master = ask_silent("Enter the master password: ")
        else:
            master = ask_master()
    
        reason = ask_normal("Enter the reason: ")
        length = ask_length()
        sys.stderr.write('Your password is:\n')
        sys.stdout.write(generate(master, reason, length) + '\n')
    
    class PWGen_Window:
        def __init__(self, gtk, silent, unsafe):
            self.gtk = gtk
            self.silent = silent
            self.unsafe = unsafe
            self.window = self.gtk.Window(self.gtk.WINDOW_TOPLEVEL)
            self.window.set_title("PWGen")
            self.window.connect("destroy", lambda w: self.gtk.main_quit())
            self.vbox = self.gtk.VBox()
    
            self.add_mastone()
            self.add_masttwo()
            self.add_reason()
            self.add_size()
            self.add_buttons()
    
            self.pwlabel = self.gtk.Label()
            self.pwlabel.set_size_request(200, 20)
            self.vbox.pack_start(self.pwlabel, True, True, 5)
    
            self.window.add(self.vbox)
            self.window.show_all()
            self.clip = self.gtk.Clipboard()
    
        def add_mastone(self):
            box = self.gtk.HBox()
            label = self.gtk.Label("The master password:")
            label.set_size_request(165, 20)
            label.set_alignment(0, 0.5)
            box.pack_start(label, False, True, 5)
            self.mastone = self.gtk.Entry()
            self.mastone.set_visibility(False)
            box.pack_start(self.mastone, True, True, 5)
            self.vbox.pack_start(box, False, False, 2)
    
        def add_masttwo(self):
            if self.unsafe:
                self.masttwo = None
            else:
                box = self.gtk.HBox()
                label = self.gtk.Label("Retype master password:")
                label.set_size_request(165, 20)
                label.set_alignment(0, 0.5)
                box.pack_start(label, False, True, 5)
                self.masttwo = self.gtk.Entry()
                self.masttwo.set_visibility(False)
                box.pack_start(self.masttwo, True, True, 5)
                self.vbox.pack_start(box, False, False, 2)
    
        def add_reason(self):
            box = self.gtk.HBox()
            label = self.gtk.Label("the reason:")
            label.set_size_request(165, 20)
            label.set_alignment(0, 0.5)
            box.pack_start(label, False, True, 5)
            self.reason = self.gtk.Entry()
            if self.silent:
                self.reason.set_visibility(False)
            box.pack_start(self.reason, True, True, 5)
            self.vbox.pack_start(box, False, False, 2)
    
        def add_size(self):
            box = self.gtk.HBox()
            label = self.gtk.Label("the password size:")
            label.set_size_request(165, 20)
            label.set_alignment(0, 0.5)
            box.pack_start(label, False, True, 5)
            self.size = self.gtk.Entry()
            self.size.set_text('10')
            if self.silent:
                self.size.set_visibility(False)
            box.pack_start(self.size, True, True, 5)
            self.vbox.pack_start(box, False, False, 2)
    
        def add_buttons(self):
            box = self.gtk.HBox()
            self.show_button = self.gtk.Button("Show password")
            self.show_button.connect("clicked", self.show_pwcallback)
            box.pack_start(self.show_button, True, True, 5)
            self.clip_button = self.gtk.Button("Copy password to clipboard")
            self.clip_button.connect("clicked", self.clip_pwcallback)
            box.pack_start(self.clip_button, True, True, 5)
            self.vbox.pack_start(box, False, False, 2)
    
        def show_pwcallback(self, data):
            if self.pwlabel.get_text():
                self.pwlabel.set_text('')
                self.show_button.set_label("Show password")
            else:
                pwd = self.generate()
                if not pwd:
                    return
                self.pwlabel.set_text(pwd)
                self.show_button.set_label("Clear password")
    
        def clip_pwcallback(self, data):
            pwd = self.generate()
            if not pwd:
                return
            self.clip.set_text(pwd)
    
        def generate(self):
            mastone = self.mastone.get_text()
            if self.masttwo:
                masttwo = self.masttwo.get_text()
            reason = self.reason.get_text()
            if self.masttwo and mastone != masttwo:
                dialog = self.gtk.MessageDialog(parent = self.window,
                                         flags = self.gtk.DIALOG_MODAL | self.gtk.DIALOG_DESTROY_WITH_PARENT,
                                         type = self.gtk.MESSAGE_WARNING,
                                         buttons = self.gtk.BUTTONS_OK,
                                         message_format = "\nThe master password is incorrect.")
                dialog.run()
                dialog.destroy()
                return
            try:
                size = int(self.size.get_text())
            except ValueError:
                dialog = self.gtk.MessageDialog(parent = self.window,
                                         flags = self.gtk.DIALOG_MODAL | self.gtk.DIALOG_DESTROY_WITH_PARENT,
                                         type = self.gtk.MESSAGE_WARNING,
                                         buttons = self.gtk.BUTTONS_OK,
                                         message_format = "\nNeed a number for size.")
                dialog.run()
                dialog.destroy()
                return
            return generate(mastone, reason, size)
    
    def main_gtk(argv):
        import pygtk
        pygtk.require('2.0')
        import gtk
        silent = False
        if '-s' in argv or '--silent' in argv:
            silent = True
        unsafe = False
        if '-u' in argv or '--unsafe' in argv:
            unsafe = True
        window = PWGen_Window(gtk, silent, unsafe)
        gtk.main()
    
    def usage(argv):
        sys.stderr.write('usage: {0:s} [options]\n'.format(argv[0])
                         + 'possible options are:\n'
                         + '    -c, --console   Don\'t open the GUI.\n'
                         + '    -s, --silent    Don\'t show the reason and password size.\n'
                         + '    -u, --unsafe    Don\'t ask to confirm the master password.\n\n')
    
    def main(argv):
        if '-h' in argv or '--help' in argv:
            usage(argv)
            return
    
        if '-c' in argv or  '--console' in argv:
            main_console(argv)
        else:
            main_gtk(argv)
    
    if __name__ == '__main__':
        main(sys.argv)
    This version also includes an other option: -u or --unsafe will not make the program ask for the master password twice. I also added a GUI that can copy the password to your clipboard without showing it
    To run the console version use the -c or --console option.
    If you use the console version I made sure all output but the password it to stderr, so you can easily pipe the password to another program or redirect it to a file.
    Last edited by ziekfiguur; October 9th, 2010 at 03:57 PM. Reason: fix typo

  7. #17
    Join Date
    Dec 2010
    Beans
    1

    Re: Quick and easy random password generator

    Zeikfiguur,

    That script is awesome!

    It should be in the default installation as far as I'm concerned.


  8. #18
    Join Date
    Nov 2009
    Location
    The Netherlands
    Beans
    239
    Distro
    Ubuntu 12.04 Precise Pangolin

    Re: Quick and easy random password generator

    Quote Originally Posted by jacobw0 View Post
    Zeikfiguur,

    That script is awesome!

    It should be in the default installation as far as I'm concerned.

    Thank you. I actually found a bug (kind of) in it a while ago. It caused some characters to have a higher probability than other characters to get in the password.
    It's not very serious, but I thought I should fix it.

    So, here is a fixed version, but please note that it is NOT compatible with the previously posted version (it will generate different passwords).
    Attached Files Attached Files

  9. #19
    Join Date
    Apr 2007
    Location
    Thimphu, Bhutan
    Beans
    23
    Distro
    Ubuntu 10.10 Maverick Meerkat

    Re: Quick and easy random password generator

    Those are some nice scripts. I think it will come handy some time.

    For now, I use a tool called 'apg' which is available in Ubuntu repos. I've found it quite good so far.

  10. #20
    Join Date
    Mar 2011
    Beans
    1

    Re: Quick and easy random password generator

    We have just been told about massive changes and conditions on password use to be implemented by July 31. This looks like an excellent script to expand on and make work. BUT .... I don't know a lick about python.

    The requirements for Passwords:


    • Must be 14 characters long.
    • Must be a mix of UPPER, lower, numbers, and special characters.
    • There can never be a sequence of 3 from any of those 4 groupings. For example I can have ABC, but not ABCD or @#$, but not @#$%.
    • It can't have any part of your name in it. I suppose this could be pulled from some $USER environment variable or from a getent passwd.


    I know this is a lot to ask, but if any brave soul should happen to take a stab at this, they would be the hero of many a Sys Admin working within the confines of Federal red tape.

Page 2 of 3 FirstFirst 123 LastLast

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •