From: Steven Tobin Date: Tue, 9 Sep 2014 02:19:25 +0000 (+1000) Subject: Improved example_import and added information to docs X-Git-Url: http://git.99rst.org/?a=commitdiff_plain;h=37b1e150156faf1f84f5731e54449a7bf6f651c8;p=redacted-XKCD-password-generator.git Improved example_import and added information to docs --- diff --git a/README.rst b/README.rst index 970f99d..7fe4ffc 100644 --- a/README.rst +++ b/README.rst @@ -97,10 +97,28 @@ A concise overview of the available ``xkcdpass`` options can be accessed via:: A large wordlist is provided (courtesy of `12Dicts `_) for convenience, but the generator can be used with any word file of the correct format: a file containing one 'word' per line. The default word file can be found in ``xkcdpass/static/default.txt``. -The main script can also be imported into other python code, and an example of this usage is provided in the package (``xkcdpass/example_import.py``). + + +Advanced Usage +============== + +The built-in functionality of ``xkcdpass`` can be extended by importing the module into custom python scripts. +An example of this usage is provided in `example_import.py `_, which randomly capitalises the letters in a generated password. + +A simple use of import:: + + import xkcdpass.xkcd_password as xp + + ## 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) + + ## create a password with the acrostic "face" + print(xp.generate_xkcdpassword(mywords, acrostic="face")) License ======= -The BSD License (BSD) \ No newline at end of file +The BSD License (BSD) diff --git a/setup.py b/setup.py index 3847e40..f534670 100644 --- a/setup.py +++ b/setup.py @@ -3,7 +3,7 @@ from setuptools import setup setup( name='xkcdpass', - version='1.2.0', + version='1.2.1', author='Steven Tobin', author_email='steventtobin@gmail.com', url='https://github.com/redacted/XKCD-password-generator', diff --git a/xkcdpass/example_import.py b/xkcdpass/example_import.py index 2dd7a25..48cd3ce 100644 --- a/xkcdpass/example_import.py +++ b/xkcdpass/example_import.py @@ -1,8 +1,22 @@ -# import the generate_xkcdpassword and generate_wordlist functions -from xkcd_password import generate_wordlist, generate_xkcdpassword +import xkcdpass.xkcd_password as xp +import random -# create a wordlist -mywords = generate_wordlist(wordfile='3esl.txt', min_length=5, max_length=8,) +## create a wordlist +#mywords = generate_wordlist(wordfile='3esl.txt', min_length=5, max_length=8,) -# create a password with the acrostic 'face' -print(generate_xkcdpassword(mywords, acrostic="face")) +## create a password with the acrostic 'face' +#print(generate_xkcdpassword(mywords, acrostic="face")) + +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) + + +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)