Skip to content

Commit

Permalink
add rudimentary password generator and strength meter
Browse files Browse the repository at this point in the history
closes #32
  • Loading branch information
Torsten Rehn committed Oct 24, 2015
1 parent e0c22da commit 0e90bae
Show file tree
Hide file tree
Showing 16 changed files with 759 additions and 1 deletion.
11 changes: 11 additions & 0 deletions bower-strip.sh
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,17 @@ rm -rvf ${BUNDLED_DIR}/font-awesome/.npmignore
# jquery
rm -rvf ${BUNDLED_DIR}/jquery/src

# password-generator
rm -rvf ${BUNDLED_DIR}/password-generator/*.html
rm -rvf ${BUNDLED_DIR}/password-generator/*.js
rm -rvf ${BUNDLED_DIR}/password-generator/*.yml
rm -rvf ${BUNDLED_DIR}/password-generator/.gitignore
rm -rvf ${BUNDLED_DIR}/password-generator/bin
rm -rvf ${BUNDLED_DIR}/password-generator/dist/password-generator.js
rm -rvf ${BUNDLED_DIR}/password-generator/lib
rm -rvf ${BUNDLED_DIR}/password-generator/Makefile
rm -rvf ${BUNDLED_DIR}/password-generator/test

# select2
rm -rvf ${BUNDLED_DIR}/select2/.gitignore
rm -rvf ${BUNDLED_DIR}/select2/component.json
Expand Down
52 changes: 52 additions & 0 deletions src/teamvault/apps/secrets/templates/secrets/secret_addedit.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@
{% endblock %}
{% block "js" %}
<script src="{% static 'bundled/card/lib/js/jquery.card.js' %}"></script>
<script src="{% static 'bundled/password-generator/dist/password-generator.min.js' %}"></script>
<script src="{% static 'bundled/select2/select2.min.js' %}"></script>
<script src="{% static 'bundled/zxcvbn/dist/zxcvbn.js' %}"></script>
{% endblock %}
{% block "content" %}

Expand Down Expand Up @@ -188,7 +190,57 @@ <h3 class="panel-title">
$(".access-details").is(':visible')? $("#access_toggle_icon").html('<i class="fa fa-plus-square-o"></i>') : $("#access_toggle_icon").html('<i class="fa fa-minus-square-o"></i>');
$(".access-details").slideToggle();
});
String.prototype.repeat = function(times) {
return (new Array(times + 1)).join(this);
};
function ratePassword () {
var score = zxcvbn($("#id_password").val(), user_inputs=[]).score + 1;
var color = "text-warning";
if (!$("#id_password").val()) {
color = "text-muted";
score = 0;
}
else if (score <= 2) {
color = "text-danger";
}
else if (score == 5) {
color = "text-success";
}
var filled_star = "<i class='fa fa-star " + color + "'></i>";
var hollow_star = "<i class='fa fa-star-o " + color + "'></i>";
$("#id_password_strength").html(filled_star.repeat(score) + hollow_star.repeat(5 - score));
}
$("#id_password").keyup(function() {
ratePassword();
$("#id_password").generated = false;
setTimeout(
function() {
if (!$("#id_password").generated) {
$("#id_password").prop("type", "password");
}
},
2000
);
});
$("#id_pwgen").focusout(function() {
setTimeout(
function() {
if (!$('#id_password').is(':focus')) {
$("#id_password").prop("type", "password");
}
},
1000
);
});
$("#id_pwgen").click(function() {
$("#id_password").val(generatePassword(32, false));
ratePassword();
$("#id_password").prop("type", "text");
$("#id_password").generated = true;
});
$(document).ready(function() {
$('[data-toggle="popover"]').popover();
$("#id_password").generated = false;
$("#id_allowed_groups").select2({
tags: true,
tokenSeparators: [",", " "],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,13 @@
<label class="control-label" for="id_password">{% trans "Password" %}</label>
</div>
<div class="col-sm-6">
<input class="form-control" id="id_password" name="password" placeholder="{% if secret %}{% trans "(unchanged)" %}{% else %}**************{% endif %}" {% if not secret %}required="required"{% endif %} type="password" value="{% if form.is_bound and not secret %}{{ form.password.value }}{% endif %}">
<div class="input-group">
<input class="form-control" id="id_password" name="password" placeholder="{% if secret %}{% trans "(unchanged)" %}{% else %}**************{% endif %}" {% if not secret %}required="required"{% endif %} type="password" value="{% if form.is_bound and not secret %}{{ form.password.value }}{% endif %}">
<span class="input-group-addon" style="border-left: 0;" title="{% trans "Password strength" %}" id="id_password_strength"><i class="fa fa-star-o text-muted"></i><i class="fa fa-star-o text-muted"></i><i class="fa fa-star-o text-muted"></i><i class="fa fa-star-o text-muted"></i><i class="fa fa-star-o text-muted"></i></span>
<span class="input-group-btn">
<button class="btn btn-default" id="id_pwgen" type="button" title="{% trans "Generate random password" %}"><i class="fa fa-refresh"></i></button>
</span>
</div>
</div>
<div class="col-sm-4">
<p class="form-control-static"><i class="fa fa-lock"></i> &nbsp; {% trans "This field will be stored securely." %}</p>
Expand Down
33 changes: 33 additions & 0 deletions src/teamvault/static/bundled/password-generator/.bower.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
"name": "password-generator",
"description": "Memorable password generator. For the command line, Node.js and browsers.",
"version": "2.0.2",
"main": "lib/password-generator.js",
"license": "MIT",
"keywords": [
"password",
"generator",
"pass",
"random",
"browser",
"crypto",
"security"
],
"authors": [
"Bermi Ferrer <bermi@bermilabs.com>"
],
"repository": {
"type": "git",
"url": "git@github.com:bermi/password-generator.git"
},
"homepage": "https://github.com/bermi/password-generator",
"_release": "2.0.2",
"_resolution": {
"type": "version",
"tag": "2.0.2",
"commit": "bda69de1a18cc4848c8c50278568559139129a60"
},
"_source": "git://github.com/bermi/password-generator.git",
"_target": "~2.0.1",
"_originalSource": "password-generator"
}
10 changes: 10 additions & 0 deletions src/teamvault/static/bundled/password-generator/.travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
language: node_js
sudo: false
node_js:
- 0.10
branches:
only:
- master
notifications:
email:
- bermi@bermilabs.com
7 changes: 7 additions & 0 deletions src/teamvault/static/bundled/password-generator/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Copyright (c) 2011 Bermi Ferrer

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
176 changes: 176 additions & 0 deletions src/teamvault/static/bundled/password-generator/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,176 @@
# password-generator

Memorable password generator. For the command line, Node.js and browsers.

[![Build Status](https://secure.travis-ci.org/bermi/password-generator.png?branch=master)](http://travis-ci.org/bermi/password-generator)

[![browser support](http://ci.testling.com/bermi/password-generator.png)](http://ci.testling.com/bermi/password-generator)

## Installation

$ npm install password-generator

## Usage

### From the CLI

password-generator -h

Displays this help

Generates a memorable password

Options:
-l Password length
-c Generates a non memorable password [default: false]
-p Pattern to match for the generated password
-h Displays this help

Simple memorable pass

password-generator
=> maqetaxaku

Custom length

password-generator -l 30
=> nugiferagiraqadamedewubaqirali

Non memorable

password-generator -c
=> QPnb3gl7_0

Customize the pattern to match for each password character

password-generator -p "[\d\W\w\p]"
=> Je;VgG?{Yd

Any number or letter

password-generator -p "[\w]"
=> 3NHPqzjIAq

Combine multiple strategies 6 memorable and 3 numbers

echo "`password-generator -l 6``password-generator -p "[0-9]" -l 3`"
=> wazawe351


### From Node.js

var generatePassword = require('password-generator');

### From the browser

<script src="https://raw.github.com/bermi/password-generator/master/dist/password-generator.min.js" type="text/javascript"></script>

#### Usage

##### Default settings (memorable 10 letters)

generatePassword() // -> xexeyimahi

##### Custom length not memorable

generatePassword(12, false) // -> 76PAGEaq6i5c

##### Characters should match a pattern

generatePassword(12, false, /\d/) // -> 252667390298

##### Customize the password prefix

generatePassword(12, false, /\d/, 'foo-') // -> foo-67390298

##### Example with custom validation rules

Given the pattern regexp can only match a single character
you can build a function that generates multiple passwords until you
hit one that complies with your rules.

The following example will generate a password with the following requirements

* Must contain at least two numbers
* Must contain at least three uppercase letters
* Must contain at least three lowercase letters
* Must contain at least two special characters
* Must NOT contain sequences of two or more repeated characters


```javascript
var generatePassword = require("password-generator");

var maxLength = 18;
var minLength = 12;
var uppercaseMinCount = 3;
var lowercaseMinCount = 3;
var numberMinCount = 2;
var specialMinCount = 2;
var UPPERCASE_RE = /([A-Z])/g;
var LOWERCASE_RE = /([a-z])/g;
var NUMBER_RE = /([\d])/g;
var SPECIAL_CHAR_RE = /([\?\-])/g;
var NON_REPEATING_CHAR_RE = /([\w\d\?\-])\1{2,}/g;

function isStrongEnough(password) {
var uc = password.match(UPPERCASE_RE);
var lc = password.match(LOWERCASE_RE);
var n = password.match(NUMBER_RE);
var sc = password.match(SPECIAL_CHAR_RE);
var nr = password.match(NON_REPEATING_CHAR_RE);
return password.length >= minLength &&
!nr &&
uc && uc.length >= uppercaseMinCount &&
lc && lc.length >= lowercaseMinCount &&
n && n.length >= numberMinCount &&
sc && sc.length >= specialMinCount;
}

function customPassword() {
var password = "";
var randomLength = Math.floor(Math.random() * (maxLength - minLength)) + minLength;
while (!isStrongEnough(password)) {
password = generatePassword(randomLength, false, /[\w\d\?\-]/);
}
return password;
}

console.log(customPassword()); // => 2hP5v?1KKNx7_a-W
```


## Running tests

npm install
make test

## Building

npm install
make all

## License

(The MIT License)

Copyright (c) 2011-2012 Bermi Ferrer &lt;bermi@bermilabs.com&gt;

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
'Software'), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 changes: 23 additions & 0 deletions src/teamvault/static/bundled/password-generator/bower.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"name": "password-generator",
"description": "Memorable password generator. For the command line, Node.js and browsers.",
"version": "2.0.1",
"main": "lib/password-generator.js",
"license": "MIT",
"keywords": [
"password",
"generator",
"pass",
"random",
"browser",
"crypto",
"security"
],
"authors": [
"Bermi Ferrer <bermi@bermilabs.com>"
],
"repository": {
"type": "git",
"url": "git@github.com:bermi/password-generator.git"
}
}

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

Loading

0 comments on commit 0e90bae

Please sign in to comment.