Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def create_user(app, username, password=None):
with app.app_context():
wordfile = xp.locate_wordfile()
mywords = xp.generate_wordlist(wordfile=wordfile, min_length=5, max_length=8)
if not password:
print("generated password: '%s'" % password)
password = xp.generate_xkcdpassword(mywords, acrostic="ambit")
assert not User.query.filter_by(username=username).scalar(), "user already exists"
user = User(username=username)
user.password = app_bcrypt.generate_password_hash(password, 10)
user.active = True
db.session.add(user)
db.session.commit()
print("created user '%s'" % user.username)
def make_password(arg_string=None):
if arg_string is None:
arg_string = "-w safe6 -n 4 --min 1 --max=6"
argv = arg_string.split()
parser = xkcd_password.XkcdPassArgumentParser(prog="xkcdpass")
options = parser.parse_args(argv)
xkcd_password.validate_options(parser, options)
my_wordlist = xkcd_password.generate_wordlist(
wordfile=options.wordfile,
min_length=options.min_length,
max_length=options.max_length,
valid_chars=options.valid_chars)
if options.verbose:
xkcd_password.verbose_reports(my_wordlist, options)
return xkcd_password.generate_xkcdpassword(
my_wordlist,
interactive=options.interactive,
numwords=options.numwords,
acrostic=options.acrostic,
delimiter=options.delimiter)
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 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))
Returns:
bool: Whether the security key is valid.
Example:
>>> mw.validate_security_key('epilogue-stilt-crux-task-corset-carton')
True
>>> mw.validate_security_key("not-A-valid-k3y")
False
'''
# check the format
if not re.match(r"\w*-\w*-\w*-\w*-\w*-\w*", security_key):
return False
wordfile = xp.locate_wordfile()
word_list = set(xp.generate_wordlist(wordfile=wordfile, min_length=0, max_length=10))
# check that the words in the security key are valid
for word in security_key.split("-"):
if word not in word_list:
return False
# check number of words
if len(security_key.split("-")) != 6:
return False
return True
def get_random_password():
wordlist = generate_wordlist()
pw = generate_xkcdpassword(wordlist, delimiter='-')
return pw
def generate_single_password(mywords=None):
import xkcdpass.xkcd_password as xp
if mywords is None:
words = xp.locate_wordfile()
mywords = xp.generate_wordlist(
wordfile=words, min_length=4, max_length=6)
return xp.generate_xkcdpassword(mywords, numwords=4)