def setUp(self): self.wordlist_full = xkcd_password.generate_wordlist( wordfile=WORDFILE, min_length=5, max_length=8,) self.wordlist_small = xkcd_password.generate_wordlist( wordfile='tests/test_list.txt', valid_chars='[a-z]')
def setUp(self): self.wordlist_full = xkcd_password.generate_wordlist( wordfile=WORDFILE, min_length=5, max_length=8, ) self.wordlist_small = xkcd_password.generate_wordlist( wordfile='tests/test_list.txt', valid_chars='[a-z]')
def generate_password(unique=False): """Generate an XKCD style password""" # create a wordlist from the default wordfile # use words between 5 and 8 letters long wordfile = xp.locate_wordfile() mywords = xp.generate_wordlist(wordfile=wordfile, min_length=5, max_length=8) # Chose a random four-letter word for acrostic acword = random.choice( # nosec xp.generate_wordlist(wordfile=wordfile, min_length=4, max_length=4)) # create a password with acrostic word pword = xp.generate_xkcdpassword(mywords, acrostic=acword) return pword
def run(self, username, password=None): with self.app_context(): if not password: wordfile = xp.locate_wordfile() mywords = xp.generate_wordlist(wordfile=wordfile, min_length=5, max_length=8) password = xp.generate_xkcdpassword(mywords, acrostic="ambit") print("generated password: '******'" % password) assert not User.query.filter_by( username=username).scalar(), "user already exists" user = User(username=username) user.password = self.app_bcrypt.generate_password_hash( password, 10) if user.password is not str: user.password = user.password.decode('utf-8') user.active = True db.session.add(user) db.session.commit() print("created user '%s' in '%s'" % (user.username, db.engine.url))
def get_pass(word_len, min_len, max_len): words = xp.locate_wordfile() mywords = xp.generate_wordlist(wordfile=words, min_length=min_len, max_length=max_len) raw_password = xp.generate_xkcdpassword(mywords, numwords=word_len) return passgen(raw_password, word_len)
def generate_password(config): wordfile = xp.locate_wordfile() words = xp.generate_wordlist(wordfile) return xp.generate_xkcdpassword( words, numwords=config["DEFAULT"].get("NumWords", 6), delimiter=config["DEFAULT"].get("Delimiter", "-"))
def main(argv=None): """Mainline code for mkpass.""" if argv is None: argv = sys.argv exit_status = 0 try: program_name = os.path.basename(argv[0]) parser = xp.XkcdPassArgumentParser(prog=program_name) parser.add_argument("-D", "--digits", action="store_true", dest="digits", default=False, help="Include random digits between words.") options = parser.parse_args(argv[1:]) xp.validate_options(parser, options) my_wordlist = xp.generate_wordlist(wordfile=options.wordfile, min_length=options.min_length, max_length=options.max_length, valid_chars=options.valid_chars) if options.verbose: xp.verbose_reports(my_wordlist, options) for words in yield_words(my_wordlist, options): xwords = [apply_transforms(word) for word in words] print(options.delimiter.join(xwords)) except SystemExit as exc: exit_status = exc.code return exit_status
def generate_new_port_password_pair(current_ports): global MIN_PORT_NUMBER, MIN_PORT_NUMBER global MIN_PASSWORD_LENGTH, MAX_PASSWORD_LENGTH ############################################################################### # 1. generate the new port ############################################################################### possible_ports = set(range(MIN_PORT_NUMBER, MAX_PORT_NUMBER + 1)) - set(current_ports) if not possible_ports: raise ValueError("Didn't have any ports to choose from!") # could also do ## new_port = possible_ports.pop() # but I was concerned that would make the port number too predictable new_port = random.choice(list(possible_ports)) ############################################################################### # 2. generate the new password ############################################################################### xkcd_wordfile = xp.locate_wordfile() xkcd_wordlist = xp.generate_wordlist(wordfile=xkcd_wordfile, max_length=5) new_password = xp.generate_xkcdpassword(xkcd_wordlist, numwords=4, delimiter='-') #new_password = xp.generate_xkcdpassword(xkcd_wordlist, acrostic="ethvpn") return str(new_port), str(new_password)
def print_poem(): """ Called on a short press of the button, in main(). Selects a poem based on the day of the month, looks for the corresponding file in the poems directory, formats the author and title, and prints it. """ PRINTER.wake() PRINTER.println("Password For: __________________") PRINTER.feed(1) from xkcdpass import xkcd_password as xp wordfile = xp.locate_wordfile() mywords = xp.generate_wordlist(wordfile=wordfile, min_length=5, max_length=8) passwd = xp.generate_xkcdpassword(mywords, numwords=4, delimiter="-") PRINTER.feed(3) PRINTER.println(passwd) PRINTER.feed(6) PRINTER.sleep()
def __init__(self): wordfile = xkcd_password.locate_wordfile() mywords = xkcd_password.generate_wordlist(wordfile=wordfile, min_length=5, max_length=8) self.name = xkcd_password.generate_xkcdpassword(mywords, acrostic="server")
def run(self, terms, variables=None, **kwargs): if not HAS_XKCDPASS: raise AnsibleLookupError( "Python xkcdpass library is required. " 'Please install using "pip install xkcdpass"') self.set_options(var_options=variables, direct=kwargs) method = self.get_option("case") delimiter = self.get_option("delimiter") max_length = self.get_option("max_length") min_length = self.get_option("min_length") numwords = self.get_option("numwords") words = xp.locate_wordfile() wordlist = xp.generate_wordlist(max_length=max_length, min_length=min_length, wordfile=words) values = xp.generate_xkcdpassword(wordlist, case=method, delimiter=delimiter, numwords=numwords) return [values]
def generate_user_password(): """Generate passwords from the xkcd library for user level accounts""" # generate password for a user level app wordfile = xkcd_password.locate_wordfile() mywords = xkcd_password.generate_wordlist(wordfile=wordfile) return xkcd_password.generate_xkcdpassword(mywords, acrostic='rock')
def cli(words, no_save, wordfile): """Generate or reset user passwords.""" global length, save, wordlist length = int(words) save = not no_save wordlist = xkcd.generate_wordlist(wordfile)
def __get_authenticated_code__(): wordfile = xp.locate_wordfile() mywords = xp.generate_wordlist(wordfile=wordfile, min_length=3, max_length=8) return xp.generate_xkcdpassword(mywords, acrostic=chr(random.randrange(97, 122)) + chr(random.randrange(97, 122)))
def generatePassphrase(wordscount=4): wordfile = xp.locate_wordfile('eff-long') mywords = xp.generate_wordlist(wordfile=wordfile, min_length=4, max_length=8) return xp.generate_xkcdpassword(mywords, numwords=wordscount, delimiter='+')
def mkpasswd(): words = xp.locate_wordfile() mywords = xp.generate_wordlist( wordfile=words, min_length=5, max_length=8 ) pwd = xp.generate_xkcdpassword(mywords) return pwd.lower()
def gen_pswrd(): word_file = xp.locate_wordfile() my_words = xp.generate_wordlist(wordfile=word_file, min_length=5, max_length=7) return xp.generate_xkcdpassword(my_words, numwords=4, delimiter="-", case='random')
def __generate_password(self): wordfile = xp.locate_wordfile() mywords = xp.generate_wordlist(wordfile=wordfile, min_length=4, max_length=5) new_pass = xp.generate_xkcdpassword(mywords, delimiter=".", numwords=4) return new_pass
def getxkcdpass(): wordfile = xp.locate_wordfile() config = xp.generate_wordlist(wordfile=wordfile, min_length=5, max_length=8) return (xp.generate_xkcdpassword(config, acrostic=False, delimiter="-", numwords=4))
def generate_password(member): from xkcdpass import xkcd_password as xp wordfile = xp.locate_wordfile() mywords = xp.generate_wordlist(wordfile=wordfile, min_length=8, max_length=10) password = xp.generate_xkcdpassword(mywords, numwords=2, delimiter='').lower().translate( None, ' -_') return (password)
def password_generator(request): wordfile = xp.locate_wordfile() words = xp.generate_wordlist(wordfile=wordfile, min_length=2, max_length=8) generated = xp.generate_xkcdpassword( words, acrostic=request.user.first_name.lower()) messages.info( request, 'Your randomly generated password is: <strong>{}</strong>'.format( generated)) return redirect('/')
def suggest_password(cls): from xkcdpass import xkcd_password as xp xp_wordfile = xp.locate_wordfile() xp_wordlist = xp.generate_wordlist( wordfile=xp_wordfile, min_length=4, max_length=6, valid_chars='[a-z]' ) suggested_password = xp.generate_xkcdpassword( xp_wordlist, numwords=4, acrostic='wild', delimiter=' ' ) return suggested_password
def __init__(self, wordfile=None, min_length=5, max_length=9, valid_chars="."): self.wordfile = xp.locate_wordfile(wordfile) self.words = xp.generate_wordlist(wordfile=wordfile, min_length=min_length, max_length=max_length, valid_chars=".") add_frequency_lists({"words": self.words})
def passphrase_generator(len=12): """ Generates a random passphrase :param len: :return: """ from xkcdpass import xkcd_password as xp wordfile = xp.locate_wordfile() mywords = xp.generate_wordlist(wordfile=wordfile, min_length=5, max_length=8) return xp.generate_xkcdpassword(mywords, numwords=len)
def _generate_passwd(length=4): """ Create an XKCD style (correct-horse-battery-staple) password. Keyword arguments: length -- Number of words to have in password """ wordfile = xp.locate_wordfile() mywords = xp.generate_wordlist(wordfile=wordfile, min_length=5, max_length=8) return xp.generate_xkcdpassword(mywords, delimiter="-", numwords=length)
def _get_words(self, options): """Locate a word file and parse it to get a list of words from which xkcdpass module will randomly choose a passphrase. The word file may be specified in the configuration file specific to a particular deployment. Otherwise the algorithm will try to locate a standard word file from well known locations. :param options: contains options for xkcdpass configuring the type of words to include. :returns: list of words """ wordfile = CONFIG['wordfile'] or xp.locate_wordfile() try: min_length = options['min_length'] except (TypeError, KeyError): min_length = 5 try: max_length = options['max_length'] except (TypeError, KeyError): max_length = 9 try: valid_chars = options['valid_chars'] except (TypeError, KeyError): valid_chars = "." # Sanity validation msg = "Invalid password generation options!" if min_length < 1 or min_length > 15: desc = ("For sanity's sake, minimum length must be " "a positive number less than or equal to 15.") raise bh.OppError(msg, desc) if max_length < 5 or max_length > 20: desc = ("For sanity's sake, maximum length must" " be a number between 5 and 20.") raise bh.OppError(msg, desc) if min_length > max_length: desc = "Minimum length cannot be larger than maximum length." raise bh.OppError(msg, desc) try: return xp.generate_wordlist(wordfile=wordfile, min_length=min_length, max_length=max_length, valid_chars=valid_chars) except Exception: raise bh.OppError("Exception during password generation!", None, 500)
def generate_password(length=4, delimiter="-", easy_mode=False): """returns a xkcd-style password""" if easy_mode == True: return generate_easy_password() wordfile = xp.locate_wordfile("ger-anlx") mywords = xp.generate_wordlist(wordfile=wordfile, min_length=3, max_length=16, valid_chars="[a-z]") password = xp.generate_xkcdpassword(mywords, numwords=length, delimiter=delimiter, case="capitalize") return password
def generate_password(self): def capitalize_first_letter(s): new_str = [] s = s.split(" ") for i, c in enumerate(s): new_str.append(c.capitalize()) return "".join(new_str) words = xp.locate_wordfile() mywords = xp.generate_wordlist(wordfile=words, min_length=5, max_length=8) raw_password = xp.generate_xkcdpassword(mywords) return capitalize_first_letter(raw_password)
def handle_creator_password(self, message): number_of_words = message.data.get("NumberOfWords") number_of_words = extract_number( number_of_words) if number_of_words else 6 acrostic = message.data.get("Acrostic") acrostic = acrostic if acrostic else False wordfile = xp.locate_wordfile() words = xp.generate_wordlist(wordfile=wordfile) # Can modify password = xp.generate_xkcdpassword(words, number_of_words, acrostic=acrostic) # Can modify self.speak_dialog('creator.password', data={'password': password})
async def start_quiz(self, data: Dict): print("Quiz registration was called") game_name = data["game_name"] participants = data["players"] participants_list = [] con = await self.pool.acquire() cur = await con.cursor() await cur.execute("SELECT id from roles WHERE name=%s", ("mobile-client", )) user_role_id = await cur.fetchone() user_role_id = user_role_id[0] game_id = await self.get_tag_id(game_name) time_stmp = datetime.datetime.now() try: await cur.execute("INSERT INTO games VALUES(%s, %s)", (game_id, time_stmp)) except Exception: print("Warning! Game was initiated before") finally: full_game_name = "com." + game_name wordfile = xp.locate_wordfile() mywords = xp.generate_wordlist(wordfile=wordfile, min_length=5, max_length=5) for user_name in participants: secret = xp.generate_xkcdpassword(mywords, acrostic="hi", delimiter=":") # secret = string.capwords(secret) await cur.execute( "INSERT INTO users(name, secret, role_id) VALUES(%s, %s, %s) RETURNING id", (user_name, secret, user_role_id)) # self.cur.execute("SELECT last_insert_rowid()") cur_user_id = await cur.fetchone() cur_user_id = cur_user_id[0] participants_list.append(cur_user_id) await cur.execute("INSERT INTO user_game VALUES(%s, %s)", (cur_user_id, game_id)) cur_game = await self.subscribe( lambda question: self.on_question_posted(game_name, question), full_game_name + ".questions") self.games[game_name] = Dbase.Game(cur_game, game_id) self.games[game_name].participants_list = participants_list print("subscribed") print(self.pool.freesize) await self.pool.release(con) return True
def get_password(): acrostic_term = request.json['text'] min_length = int(request.json['min_length']) max_length = int(request.json['max_length']) print('term', acrostic_term) # create a wordlist from the default wordfile # use words between 5 and 8 letters long wordfile = xp.locate_wordfile() mywords = xp.generate_wordlist(wordfile=wordfile, min_length=min_length, max_length=max_length, valid_chars='.') # create a password with the acrostic "face" print(xp.generate_xkcdpassword(mywords, acrostic=acrostic_term)) return xp.generate_xkcdpassword(mywords, acrostic=acrostic_term)
def run(self, username, password=None): with self.app_context(): if not password: wordfile = xp.locate_wordfile() mywords = xp.generate_wordlist(wordfile=wordfile, min_length=5, max_length=8) password = xp.generate_xkcdpassword(mywords, acrostic="ambit") print("generated password: '******'" % password) assert not User.query.filter_by(username=username).scalar(), "user already exists" user = User(username=username) user.password = self.app_bcrypt.generate_password_hash(password, 10) user.active = True db.session.add(user) db.session.commit() print("created user '%s' in '%s'" % (user.username, db.engine.url))
def json_password_generator(request): # Example Django view to generate passphrase suggestions via xkcd library # Called with optional params e.g. # /json_password_generator/?tc=true&separator=|&acrostic=face if request.method == 'GET': acrostic = request.GET.get("acrostic", None) titlecase = request.GET.get("tc", None) wordfile = xp.locate_wordfile() words = xp.generate_wordlist( wordfile=wordfile, min_length=3, max_length=8) suggestion = xp.generate_xkcdpassword(words, acrostic=acrostic) if titlecase: # Convert "foo bar" to "Foo Bar" suggestion = suggestion.title() return JsonResponse({ 'suggestion': suggestion} )
import random import xkcdpass.xkcd_password as xp def random_capitalisation(s, chance): new_str = [] for i, c in enumerate(s): new_str.append(c.upper() if random.random() < chance else c) return "".join(new_str) def capitalize_first_letter(s): new_str = [] s = s.split(" ") for i, c in enumerate(s): new_str.append(c.capitalize()) return "".join(new_str) words = xp.locate_wordfile() mywords = xp.generate_wordlist(wordfile=words, min_length=5, max_length=8) raw_password = xp.generate_xkcdpassword(mywords) for i in range(5): print(random_capitalisation(raw_password, i/10.0)) print(capitalize_first_letter(raw_password))
def generate_password(): from xkcdpass import xkcd_password as xp mywords = xp.generate_wordlist() return xp.generate_xkcdpassword(mywords, numwords=4)
def main(wf): # Imports go here. from xkcdpass import xkcd_password as xp import string from random import SystemRandom def genpw(size, chars): return ''.join(SystemRandom().choice(chars) for _ in range(size)) # Defaults defaults = { 'password_length': 10, 'xkcd_delimiter': '-', 'xkcd_minlength': 4, 'xkcd_maxlength': 10, 'xkcd_wordllist': 'eff-long', # eff-long (English), spa-mich (Spanish), fin-kotus (Finnish),ita-wiki (Italian), ger-anlx (German) } # ================================= MAIN =================================== # Get args from Workflow, already in normalized Unicode password_length = defaults['password_length'] if len(wf.args) >= 1: try: password_length = int(wf.args[0].strip()) except ValueError: pass # XKCD options # TODO: add possibility to change options xkcd_wordfile = defaults['xkcd_wordllist'] xkcd_min_length = defaults['xkcd_minlength'] xkcd_max_length = defaults['xkcd_maxlength'] xkcd_delimiter = defaults['xkcd_delimiter'] # Get XKCD Wordlist and passwords mywords = xp.generate_wordlist(wordfile=xkcd_wordfile, min_length=xkcd_min_length, max_length=xkcd_max_length) xkcd_3 = xp.generate_xkcdpassword(mywords, 3, False, False, xkcd_delimiter) xkcd_4 = xp.generate_xkcdpassword(mywords, 4, False, False, xkcd_delimiter) # Allowed Special Characters # https://www.owasp.org/index.php/Password_special_characters special_chars = "!\"#$%&'()*+,-./:;<=>?@[\]^_`{|}~" full_pw_charset = string.ascii_uppercase + string.ascii_lowercase + string.digits + special_chars alnum_pw_charset = string.ascii_uppercase + string.ascii_lowercase + string.digits # Generate passwords full_pw = genpw(password_length, full_pw_charset) alnum_pw = genpw(password_length, alnum_pw_charset) # Update workflow if a new version is available. if wf.update_available is True: wf.add_item('New version available', 'Press enter to install the update.', autocomplete='workflow:update', icon=ICON_INFO ) # Add password items wf.add_item('%d character password' % password_length, full_pw, valid=True, arg=full_pw) wf.add_item('%d character password (no special characters)' % password_length, alnum_pw, valid=True, arg=alnum_pw) wf.add_item('XKCD Password (3 words)', xkcd_3, valid=True, arg=xkcd_3) wf.add_item('XKCD Password (4 words)', xkcd_4, valid=True, arg=xkcd_4) # Send output to Alfred. wf.send_feedback() return 0
def mkpasswd(): words = xp.locate_wordfile() mywords = xp.generate_wordlist(wordfile=words, min_length=5, max_length=8) pwd = xp.generate_xkcdpassword(mywords) return pwd.lower()
thumb_height=64, thumb_width=64, ) ] bot.answer_inline_query(inline_query_id=query.id, results=results, cache_time=1, is_personal=True) if config.botan_id: botan.track(config.botan_api_key, -1, {}, 'Inline Mode') return class WebhookServer(object): """ This is my custom CherryPyServer Object for use with Nginx backend. You may want to get original WebhookServer object here: http://bit.ly/29ETlEy """ @cherrypy.expose def index(self): length = int(cherrypy.request.headers['content-length']) json_string = cherrypy.request.body.read(length).decode("utf-8") update = telebot.types.Update.de_json(json_string) bot.process_new_updates([update]) return '' if __name__ == '__main__': global wordlist wordlist = xp.generate_wordlist(wordfile=config.words_file, min_length=4, max_length=10, valid_chars="[a-z]") # You may want to use webhooks here... bot.polling(none_stop=True)
def generate_password(member): from xkcdpass import xkcd_password as xp wordfile = xp.locate_wordfile() mywords = xp.generate_wordlist(wordfile=wordfile, min_length=8, max_length=10) password = xp.generate_xkcdpassword(mywords, numwords=2, delimiter='').lower().translate(None, ' -_') return(password)
from sqlalchemy import Column from sqlalchemy import Unicode from sqlalchemy import Integer from sqlalchemy import DateTime from sqlalchemy import ForeignKey from sqlalchemy.orm import relation from sqlalchemy.orm import backref import pydiditpyramidgateway.models.meta from pydiditpyramidgateway.models.User import User from xkcdpass import xkcd_password short_token_wordlist = xkcd_password.generate_wordlist() Base = pydiditpyramidgateway.models.meta.Base class InitialToken(Base): '''InitialToken object''' __tablename__ = 'initial_tokens' user_id = Column( Integer, ForeignKey('users.id'), nullable=False, primary_key=True ) token = Column(Unicode(length=255), nullable=False)