Skip to content

Commit

Permalink
More PasswordRequirements options
Browse files Browse the repository at this point in the history
Added check_breaches which uses check_password and func which uses a custom function
  • Loading branch information
bsoyka committed Jul 26, 2020
1 parent 979aa23 commit 1102eaa
Show file tree
Hide file tree
Showing 17 changed files with 85 additions and 39 deletions.
2 changes: 1 addition & 1 deletion .bumpversion.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[bumpversion]
current_version = 1.0.0
current_version = 1.1.0

[bumpversion:file:passwd/__init__.py]

Expand Down
6 changes: 3 additions & 3 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ passwd
.. image:: https://github.com/bsoyka/passwd/workflows/Testing%20with%20pytest/badge.svg?event=push
:target: https://github.com/bsoyka/passwd/actions
:alt: Testing with pytest
.. image:: https://img.shields.io/badge/version-1.0.0-orange
:target: https://github.com/bsoyka/passwd/releases/tag/v1.0.0
:alt: Version 1.0.0
.. image:: https://img.shields.io/badge/version-1.1.0-orange
:target: https://github.com/bsoyka/passwd/releases/tag/v1.1.0
:alt: Version 1.1.0
.. image:: https://img.shields.io/pypi/l/passwd
:target: https://github.com/bsoyka/passwd/blob/master/LICENSE
:alt: MIT License
Expand Down
2 changes: 1 addition & 1 deletion docs/.buildinfo
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Sphinx build info version 1
# This file hashes the configuration used when building these files. When it is not found, a full rebuild will be done.
config: d45651525e101ee4e4315937caaf2a7d
config: 6759815ba9a96602f0dd1217fcd60801
tags: 645f666f9bcd5a90fca523b33c5a78b7
4 changes: 2 additions & 2 deletions docs/_modules/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

<meta name="viewport" content="width=device-width, initial-scale=1.0">

<title>Overview: module code &mdash; passwd 1.0.0 documentation</title>
<title>Overview: module code &mdash; passwd 1.1.0 documentation</title>



Expand Down Expand Up @@ -59,7 +59,7 @@


<div class="version">
1.0.0
1.1.0
</div>


Expand Down
23 changes: 17 additions & 6 deletions docs/_modules/passwd.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

<meta name="viewport" content="width=device-width, initial-scale=1.0">

<title>passwd &mdash; passwd 1.0.0 documentation</title>
<title>passwd &mdash; passwd 1.1.0 documentation</title>



Expand Down Expand Up @@ -59,7 +59,7 @@


<div class="version">
1.0.0
1.1.0
</div>


Expand Down Expand Up @@ -151,7 +151,7 @@
<div itemprop="articleBody">

<h1>Source code for passwd</h1><div class="highlight"><pre>
<span></span><span class="n">__version__</span> <span class="o">=</span> <span class="s2">&quot;1.0.0&quot;</span>
<span></span><span class="n">__version__</span> <span class="o">=</span> <span class="s2">&quot;1.1.0&quot;</span>

<span class="kn">import</span> <span class="nn">hashlib</span>
<span class="kn">from</span> <span class="nn">collections</span> <span class="kn">import</span> <span class="n">Counter</span>
Expand Down Expand Up @@ -203,9 +203,8 @@ <h1>Source code for passwd</h1><div class="highlight"><pre>
<span class="sd"> min_alpha (int): The minimum number of alphabetical characters in the password</span>
<span class="sd"> min_upper (int): The minimum number of uppercase letters in the password</span>
<span class="sd"> min_lower (int): The minimum number of lowercase letters in the password</span>

<span class="sd"> Todo:</span>
<span class="sd"> Use the :meth:`~passwd.check_password` method as a requirement option</span>
<span class="sd"> check_breaches (bool): Whether to ensure that passwords aren&#39;t found in known data breaches (uses :meth:`~passwd.check_password`)</span>
<span class="sd"> func (function): A function that takes in a password (:class:`str`) and returns a :class:`bool` that must be ``True`` for the password to meet all requirements</span>
<span class="sd"> &quot;&quot;&quot;</span>

<span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span>
Expand All @@ -217,13 +216,17 @@ <h1>Source code for passwd</h1><div class="highlight"><pre>
<span class="n">min_alpha</span><span class="o">=</span><span class="mi">0</span><span class="p">,</span>
<span class="n">min_upper</span><span class="o">=</span><span class="mi">0</span><span class="p">,</span>
<span class="n">min_lower</span><span class="o">=</span><span class="mi">0</span><span class="p">,</span>
<span class="n">check_breaches</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span>
<span class="n">func</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
<span class="p">):</span>
<span class="bp">self</span><span class="o">.</span><span class="n">min_length</span> <span class="o">=</span> <span class="n">min_length</span>
<span class="bp">self</span><span class="o">.</span><span class="n">min_digits</span> <span class="o">=</span> <span class="n">min_digits</span>
<span class="bp">self</span><span class="o">.</span><span class="n">min_special</span> <span class="o">=</span> <span class="n">min_special</span>
<span class="bp">self</span><span class="o">.</span><span class="n">min_alpha</span> <span class="o">=</span> <span class="n">min_alpha</span>
<span class="bp">self</span><span class="o">.</span><span class="n">min_upper</span> <span class="o">=</span> <span class="n">min_upper</span>
<span class="bp">self</span><span class="o">.</span><span class="n">min_lower</span> <span class="o">=</span> <span class="n">min_lower</span>
<span class="bp">self</span><span class="o">.</span><span class="n">check_breaches</span> <span class="o">=</span> <span class="n">check_breaches</span>
<span class="bp">self</span><span class="o">.</span><span class="n">func</span> <span class="o">=</span> <span class="n">func</span>

<div class="viewcode-block" id="PasswordRequirements.check"><a class="viewcode-back" href="../checking.html#passwd.PasswordRequirements.check">[docs]</a> <span class="k">def</span> <span class="nf">check</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">password</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;Check a password against the requirements</span>
Expand Down Expand Up @@ -262,6 +265,14 @@ <h1>Source code for passwd</h1><div class="highlight"><pre>
<span class="k">if</span> <span class="n">lower_chars</span> <span class="o">&lt;</span> <span class="bp">self</span><span class="o">.</span><span class="n">min_lower</span><span class="p">:</span>
<span class="k">return</span> <span class="kc">False</span>

<span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">check_breaches</span><span class="p">:</span>
<span class="k">if</span> <span class="n">check_password</span><span class="p">(</span><span class="n">password</span><span class="p">):</span>
<span class="k">return</span> <span class="kc">False</span>

<span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">func</span><span class="p">:</span>
<span class="k">if</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">func</span><span class="p">(</span><span class="n">password</span><span class="p">):</span>
<span class="k">return</span> <span class="kc">False</span>

<span class="k">return</span> <span class="kc">True</span></div></div>


Expand Down
2 changes: 1 addition & 1 deletion docs/_static/documentation_options.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
var DOCUMENTATION_OPTIONS = {
URL_ROOT: document.getElementById("documentation_options").getAttribute('data-url_root'),
VERSION: '1.0.0',
VERSION: '1.1.0',
LANGUAGE: 'None',
COLLAPSE_INDEX: false,
BUILDER: 'html',
Expand Down
12 changes: 5 additions & 7 deletions docs/checking.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

<meta name="viewport" content="width=device-width, initial-scale=1.0">

<title>Password Checking &mdash; passwd 1.0.0 documentation</title>
<title>Password Checking &mdash; passwd 1.1.0 documentation</title>



Expand Down Expand Up @@ -61,7 +61,7 @@


<div class="version">
1.0.0
1.1.0
</div>


Expand Down Expand Up @@ -158,7 +158,7 @@
<h1>Password Checking<a class="headerlink" href="#password-checking" title="Permalink to this headline"></a></h1>
<dl class="py class">
<dt id="passwd.PasswordRequirements">
<em class="property">class </em><code class="sig-prename descclassname">passwd.</code><code class="sig-name descname">PasswordRequirements</code><span class="sig-paren">(</span><em class="sig-param"><span class="o">*</span></em>, <em class="sig-param"><span class="n">min_length</span><span class="o">=</span><span class="default_value">0</span></em>, <em class="sig-param"><span class="n">min_digits</span><span class="o">=</span><span class="default_value">0</span></em>, <em class="sig-param"><span class="n">min_special</span><span class="o">=</span><span class="default_value">0</span></em>, <em class="sig-param"><span class="n">min_alpha</span><span class="o">=</span><span class="default_value">0</span></em>, <em class="sig-param"><span class="n">min_upper</span><span class="o">=</span><span class="default_value">0</span></em>, <em class="sig-param"><span class="n">min_lower</span><span class="o">=</span><span class="default_value">0</span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/passwd.html#PasswordRequirements"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#passwd.PasswordRequirements" title="Permalink to this definition"></a></dt>
<em class="property">class </em><code class="sig-prename descclassname">passwd.</code><code class="sig-name descname">PasswordRequirements</code><span class="sig-paren">(</span><em class="sig-param"><span class="o">*</span></em>, <em class="sig-param"><span class="n">min_length</span><span class="o">=</span><span class="default_value">0</span></em>, <em class="sig-param"><span class="n">min_digits</span><span class="o">=</span><span class="default_value">0</span></em>, <em class="sig-param"><span class="n">min_special</span><span class="o">=</span><span class="default_value">0</span></em>, <em class="sig-param"><span class="n">min_alpha</span><span class="o">=</span><span class="default_value">0</span></em>, <em class="sig-param"><span class="n">min_upper</span><span class="o">=</span><span class="default_value">0</span></em>, <em class="sig-param"><span class="n">min_lower</span><span class="o">=</span><span class="default_value">0</span></em>, <em class="sig-param"><span class="n">check_breaches</span><span class="o">=</span><span class="default_value">False</span></em>, <em class="sig-param"><span class="n">func</span><span class="o">=</span><span class="default_value">None</span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/passwd.html#PasswordRequirements"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#passwd.PasswordRequirements" title="Permalink to this definition"></a></dt>
<dd><p>A set of requirements to check passwords against</p>
<dl class="field-list simple">
<dt class="field-odd">Keyword Arguments</dt>
Expand All @@ -169,13 +169,11 @@ <h1>Password Checking<a class="headerlink" href="#password-checking" title="Perm
<li><p><strong>min_alpha</strong> (<em>int</em>) – The minimum number of alphabetical characters in the password</p></li>
<li><p><strong>min_upper</strong> (<em>int</em>) – The minimum number of uppercase letters in the password</p></li>
<li><p><strong>min_lower</strong> (<em>int</em>) – The minimum number of lowercase letters in the password</p></li>
<li><p><strong>check_breaches</strong> (<em>bool</em>) – Whether to ensure that passwords aren’t found in known data breaches (uses <a class="reference internal" href="#passwd.check_password" title="passwd.check_password"><code class="xref py py-meth docutils literal notranslate"><span class="pre">check_password()</span></code></a>)</p></li>
<li><p><strong>func</strong> (<em>function</em>) – A function that takes in a password (<code class="xref py py-class docutils literal notranslate"><span class="pre">str</span></code>) and returns a <code class="xref py py-class docutils literal notranslate"><span class="pre">bool</span></code> that must be <code class="docutils literal notranslate"><span class="pre">True</span></code> for the password to meet all requirements</p></li>
</ul>
</dd>
</dl>
<div class="admonition-todo admonition" id="id1">
<p class="admonition-title">Todo</p>
<p>Use the <a class="reference internal" href="#passwd.check_password" title="passwd.check_password"><code class="xref py py-meth docutils literal notranslate"><span class="pre">check_password()</span></code></a> method as a requirement option</p>
</div>
<dl class="py method">
<dt id="passwd.PasswordRequirements.check">
<code class="sig-name descname">check</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">password</span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/passwd.html#PasswordRequirements.check"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#passwd.PasswordRequirements.check" title="Permalink to this definition"></a></dt>
Expand Down
4 changes: 2 additions & 2 deletions docs/generation.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

<meta name="viewport" content="width=device-width, initial-scale=1.0">

<title>Password Generation &mdash; passwd 1.0.0 documentation</title>
<title>Password Generation &mdash; passwd 1.1.0 documentation</title>



Expand Down Expand Up @@ -60,7 +60,7 @@


<div class="version">
1.0.0
1.1.0
</div>


Expand Down
4 changes: 2 additions & 2 deletions docs/genindex.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

<meta name="viewport" content="width=device-width, initial-scale=1.0">

<title>Index &mdash; passwd 1.0.0 documentation</title>
<title>Index &mdash; passwd 1.1.0 documentation</title>



Expand Down Expand Up @@ -59,7 +59,7 @@


<div class="version">
1.0.0
1.1.0
</div>


Expand Down
6 changes: 3 additions & 3 deletions docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

<meta name="viewport" content="width=device-width, initial-scale=1.0">

<title>passwd &mdash; passwd 1.0.0 documentation</title>
<title>passwd &mdash; passwd 1.1.0 documentation</title>



Expand Down Expand Up @@ -60,7 +60,7 @@


<div class="version">
1.0.0
1.1.0
</div>


Expand Down Expand Up @@ -156,7 +156,7 @@
<div class="section" id="passwd">
<h1>passwd<a class="headerlink" href="#passwd" title="Permalink to this headline"></a></h1>
<a class="reference external image-reference" href="https://github.com/bsoyka/passwd/actions"><img alt="Testing with pytest" src="https://github.com/bsoyka/passwd/workflows/Testing%20with%20pytest/badge.svg?event=push" /></a>
<a class="reference external image-reference" href="https://github.com/bsoyka/passwd/releases/tag/v1.0.0"><img alt="Version 1.0.0" src="https://img.shields.io/badge/version-1.0.0-orange" /></a>
<a class="reference external image-reference" href="https://github.com/bsoyka/passwd/releases/tag/v1.1.0"><img alt="Version 1.1.0" src="https://img.shields.io/badge/version-1.1.0-orange" /></a>
<a class="reference external image-reference" href="https://github.com/bsoyka/passwd/blob/master/LICENSE"><img alt="MIT License" src="https://img.shields.io/pypi/l/passwd" /></a>
<a class="reference external image-reference" href="https://bsoyka.github.io/passwd"><img alt="Documentation" src="https://img.shields.io/badge/documentation-blue" /></a>
<a class="reference external image-reference" href="https://github.com/bsoyka/passwd/issues"><img alt="GitHub Issues" src="https://img.shields.io/github/issues/bsoyka/passwd" /></a>
Expand Down
2 changes: 1 addition & 1 deletion docs/objects.inv
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Sphinx inventory version 2
# Project: passwd
# Version: 1.0.0
# Version: 1.1.0
# The remainder of this file is compressed using zlib.
xڍ��� ��<�^��k�&�>�AX�F
4ڷ�j�ƞ 3��*b̛ř;�f)��J�U�Pު��s/�Rą��n�#�V�8��T` ɶ5\�U�*֌��g)�M`ܥ'O��qS��1�ZP��E�W��,a��h�����1�h{L͖1p��pd)|:��;�@v��NX�%����l�L5Qo��Y��C����i7-���i1�晫�3��Zr�
Expand Down
4 changes: 2 additions & 2 deletions docs/search.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

<meta name="viewport" content="width=device-width, initial-scale=1.0">

<title>Search &mdash; passwd 1.0.0 documentation</title>
<title>Search &mdash; passwd 1.1.0 documentation</title>



Expand Down Expand Up @@ -61,7 +61,7 @@


<div class="version">
1.0.0
1.1.0
</div>


Expand Down
2 changes: 1 addition & 1 deletion docs/searchindex.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 1102eaa

Please sign in to comment.