Project

General

Profile

1 2 Manuela
/**
2
 * https://github.com/webdynamik/password-generator
3
 */
4
// passwort-generator.js
5
// http://passwort-generieren.de
6
// (c) 2014 Jan Krause
7
(function() {
8
    "use strict";
9
10
    var root = this;
11
12
    var PasswordGenerator = function(options) {
13
        if(!options){
14
            options = {};
15
            options.el = document.body;
16
console.info( options );
17
        }
18
19
        this.options = this.extend(options, this.default_options);
20
    };
21
22
    // Export the object for **Node.js**
23
    if (typeof exports !== 'undefined') {
24
        if (typeof module !== 'undefined' && module.exports) {
25
            exports = module.exports = PasswordGenerator;
26
        }
27
        exports.PasswordGenerator = PasswordGenerator;
28
    } else {
29
        root.PasswordGenerator = PasswordGenerator;
30
    }
31
32
    PasswordGenerator.prototype = {
33
        options: {},
34
        default_options: {
35
            length: 8,
36
            lowercase: true,
37
            uppercase: true,
38
            numbers: true,
39
            special_character: true,
40
            brackets: true,
41
            minus: true,
42
            underscore: true,
43
            space: true
44
        },
45
        _passwort: '',
46
47
        extend: function(options,defaults){
48
            var extended = {};
49
            var prop;
50
            for (prop in defaults) {
51
                if (Object.prototype.hasOwnProperty.call(defaults, prop)) {
52
                    extended[prop] = defaults[prop];
53
                }
54
            }
55
            for (prop in options) {
56
                if (Object.prototype.hasOwnProperty.call(options, prop)) {
57
                    extended[prop] = options[prop];
58
                }
59
            }
60
            return extended;
61
        },
62
63
        generate: function() {
64
            var _i, _len, _passwortString = '';
65
66
            if(this.options.lowercase){
67
                _passwortString += 'abcdefghijklmnopqrstuvwxyz';
68
            }
69
70
            if(this.options.uppercase){
71
                _passwortString += 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
72
            }
73
74
            if(this.options.numbers){
75
                _passwortString += '0123456789';
76
            }
77
78
            if(this.options.special_character){
79
                _passwortString += ',.;:#+~*=&%$§!|/€@""^°`´\'\\';
80
            }
81
82
            if(this.options.brackets){
83
                _passwortString += '<>[](){}';
84
            }
85
86
            if(this.options.minus){
87
                _passwortString += '-';
88
            }
89
90
            if(this.options.underscore){
91
                _passwortString += '_';
92
            }
93
94
            if(this.options.space){
95
                _passwortString += ' ';
96
            }
97
98
            this._passwort = '';
99
            for (_i = 0, _len = this.options.length; _i < _len; _i++) {
100
                this._passwort += _passwortString.charAt(Math.floor(Math.random() * _passwortString.length));
101
            }
102
        },
103
104
        set: function(param) {
105
            this.options = this.extend(param,this.options);
106
console.info( this.options );
107
        },
108
109
        get: function() {
110
            this.generate();
111
            return this._passwort;
112
        },
113
114
        render: function() {
115
            this.options.el.value  = this.get();
116
            this.options.el2.value = ''; //this._passwort;
117
        }
118
    };
119
120
}.call(this));