Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_acrostic(self):
word = "face"
result = xkcd_password.generate_xkcdpassword(
self.wordlist_small,
acrostic=word)
self.assertEqual("".join(map(lambda x: x[0], result.split())), word)
def test_delim(self):
tdelim = "_"
result = xkcd_password.generate_xkcdpassword(
self.wordlist_small,
delimiter=tdelim)
self.assertIsNotNone(re.match('([a-z]+(_|$))+', result))
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 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: '%s'" % 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 generate_security_key():
'''Generates a human-friendly cryptographically secure security keys.
Returns:
str: A security key consisting of six words delimited by dashes
Example:
>>> mw.generate_security_key()
'epilogue-stilt-crux-task-corset-carton'
'''
wordfile = xp.locate_wordfile()
word_list = xp.generate_wordlist(wordfile=wordfile, min_length=0, max_length=10)
while True:
key = xp.generate_xkcdpassword(word_list, delimiter="-")
if validate_security_key(key): # ensure key is valid
return key
def get_random_password():
wordlist = generate_wordlist()
pw = generate_xkcdpassword(wordlist, delimiter='-')
return pw
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',