Skip to content

Commit

Permalink
refactor: changed how characters are generated.
Browse files Browse the repository at this point in the history
This update changes how the `generateCharCode` function generates
characters. The new method will allow for the expansion of more
characters by removing the manual `if else` chaining. Furthermore we
also removed the `conformPassword` check step as the new method will
always ensure the proper number of attributes exists in the password (at
the cost of possibly being a bit less random).

This update includes the following changes:
* The `generateCharCode` function now recieves a new parameter, a
`charCodeRequest` object which contains a string that is the desired
character we want to generate. The checks are now performed against a
`characterCodeConstraints` object which contains the attributes for each
character type.
* Removed the `conformPassword` function.
* Moved all Interfaces, Enums, Lists and Objects into a Data folder.
* Removed any currently unused modifiers such as, *memorable* and
*special*
* Updated the README
* Updated the Demo page:
	* Clarified the character set being used.
	* Added a warning about excessive use of the *exclude characters*
feature
	* Removed unneeded JavaScript code for the demo
* Updates to the `package.json` file:
	* removed the `main` attribute, replaced with `browser`
	* Updated version.
	* Added more directories.
	* Changed the `license` attribute to `licenses` and added a URL.
* Added two new helper functions:
	* `shuffle` used to shuffle arrays.
	* `createModifierList` creates a list of modifiers from an object.

Signed-off-by: staticBanter <[email protected]>
  • Loading branch information
staticBanter committed Nov 3, 2022
1 parent 143da60 commit 416dde3
Show file tree
Hide file tree
Showing 38 changed files with 677 additions and 412 deletions.
29 changes: 15 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
simplePass
=

> [!CAUTION]
> This project is still in development. Certain features are incomplete or may not function entirely. **Use At Your Own Risk**
> **CAUTION**
>
> This project is in Beta Phase. Some features may still contain a few bugs.
- [simplePass](#simplepass)
- [About](#about)
- [Installation](#installation)
- [Modifier(Options)](#modifieroptions)
- [General Modifiers](#general-modifiers)
- [Whitespace Modifiers](#whitespace-modifiers)
- [Latin Basic Modifiers](#latin-basic-modifiers)
- [Examples](#examples)
- [Development](#development)
- [Requirements](#requirements)
Expand All @@ -25,7 +29,7 @@ simplePass is a JavaScript password generator.
To include simplePass in your project follow these steps:

1. Download the ```simplePass``` directory.
2. simplePass is built using *ESNext* Modules imports so in your project you will have to import simplePass like so:
2. simplePass is built using *ESNext* module imports so in your project you will have to import simplePass like so:
```javascript
import simplePass from 'yourLocalPathing/simplePass/simplePass.js';
```
Expand All @@ -38,28 +42,25 @@ const password = simplePass(modifier);

simplePass may be called a variety of modifiers to change the desired passwords outcome. These modifiers are passed as an object to simplePass.

## General Modifiers
* length:*number* - The length of the password (default: 8)
* min: 3
* max 256
* lowercase:*boolean* - Ensure lowercase characters (default: true)
* uppercase:*boolean* - Ensure uppercase characters (default: false)
* numbers:*boolean* - Ensure numbers (default: false)
* punctuation:*boolean* - Ensure punctuation (default: false)
* excludeCharacters: *string* - Ensure the following characters are excluded from the password (default: empty)
* special:*boolean* - Ensure special characters (default: false) **disabled**
* memorable: *boolean* - Create a password using a series of regular words (ie HorseRulerBatteryStapler) (default: false). **disabled**
* **Whitespace Options**

### Whitespace Modifiers
* w_beginning: *boolean* - Allow whitespace at the beginning of a password.
* w_beginning_required: *boolean* - Ensure a whitespace character at the beginning of a password.
* w_end: *boolean* - Allow whitespace at the end of a password.
* w_end_required: *boolean* - Ensure a whitespace character at the end of a password.
* w_between: *boolean* - Ensure a whitespace character between the beginning and end of a password.

> [!CAUTION]
> The *special* option currently does not work and will be silently ignored.
## Latin Basic Modifiers
* lowercase:*boolean* - Ensure a lowercase characters (default: true)
* uppercase:*boolean* - Ensure uppercase characters (default: false)
* numbers:*boolean* - Ensure numbers (default: false)
* punctuation:*boolean* - Ensure punctuation (default: false)

> [!CAUTION]
> The *memorable* option currently does not work and will be silently ignored.

# Examples

Expand Down
38 changes: 17 additions & 21 deletions demo.html
Original file line number Diff line number Diff line change
Expand Up @@ -29,27 +29,22 @@ <h2>Modifiers</h2>
<label>Length:
<input type="number" form="passwordForm" name="length" max="256" min="1" step="1" value="8" required/>
</label>
<label>Lower Case:
<input type="checkbox" form="passwordForm" name="lowercase" checked/>
</label>
<label>Upper Case:
<input type="checkbox" form="passwordForm" name="uppercase" />
</label>
<label>Numbers:
<input type="checkbox" form="passwordForm" name="numbers" />
</label>
<label>Punctuation:
<input type="checkbox" form="passwordForm" name="punctuation" />
</label>
<label>Special Chars(Emojis, Unicode Symbols):
<input type="checkbox" form="passwordForm" name="special" disabled/>
</label>
<label>Memorable:
<input type="checkbox" form="passwordForm" name="memorable" disabled/>
</label>
<label>Allow Whitespace:
<input type="checkbox" form="passwordForm" name="allow_whitespace">
</label>
<fieldset>
<legend>Latin Basic</legend>
<p>This does not include Control Characters 0-31,127</p>
<label>Lower Case:
<input type="checkbox" form="passwordForm" name="lowercase" checked/>
</label>
<label>Upper Case:
<input type="checkbox" form="passwordForm" name="uppercase" />
</label>
<label>Numbers:
<input type="checkbox" form="passwordForm" name="numbers" />
</label>
<label>Punctuation:
<input type="checkbox" form="passwordForm" name="punctuation" />
</label>
</fieldset>
<fieldset id="whitespaceOptions" name="whitespaceOptions" form="passwordForm">
<legend>Whitespace Options</legend>
<fieldset>
Expand All @@ -76,6 +71,7 @@ <h2>Modifiers</h2>
</fieldset>
<label>Exclude Characters:
<input type="text" form="passwordForm" name="excludeCharacters" />
<p>* <strong>Warning</strong>: Excessive use of this feature may result in degraded performance or non-performance of the program. *</p>
</label>
</form>
</main>
Expand Down
3 changes: 3 additions & 0 deletions demo/demo.css
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@
border: 1px solid;
border-radius: 0 0 10px 10px;
box-shadow: 0 1px 5px;
}

#passwordForm > fieldset{
display: flex;
flex-flow: column;
}
Expand Down
23 changes: 0 additions & 23 deletions demo/demo.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,29 +8,6 @@ import simplePass from "../simplePass/simplePass.js";
const displayPassword = document.body.querySelector("#displayPassword");
displayPassword.innerText = simplePass();

// Hide the whitespace options until a user decides to modify them.
const whitespaceFieldSet = document.body.querySelector('#whitespaceOptions');
whitespaceFieldSet.setAttribute('hidden','hidden');

// Disable the whitespace options until a user decides to use them.
const whitespaceOptions = whitespaceFieldSet.querySelectorAll('input');
whitespaceOptions.forEach((option)=>{option.setAttribute('disabled','disabled');});

/**
* If the 'allow whitespace' option is set then unhide the whitespace options and enable them,
* Else hide the options and disable them.
*/
document.body.querySelector("input[name='allow_whitespace']").addEventListener('input',function(){

if(this.checked){
whitespaceFieldSet.removeAttribute('hidden');
whitespaceOptions.forEach((option)=>{option.removeAttribute('disabled');});
}else{
whitespaceFieldSet.setAttribute('hidden','hidden');
whitespaceOptions.forEach((option)=>{option.setAttribute('disabled','disabled');});
}
});

// When the user submits the form, call simplePass and display the new form.
document.body.querySelector("#passwordForm").addEventListener('submit',function(event){
event.preventDefault();
Expand Down
15 changes: 11 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@
},
"name": "simplepass",
"description": "simplePass is a Javascript password generator.",
"version": "2.5.1-Development",
"main": "bs-config.js",
"version": "1.0.0-Beta",
"browser": "./simplePass/simplePass.js",
"directories": {
"test": "test"
"test": "test",
"src": "src",
"lib": "simplePass"
},
"repository": {
"type": "git",
Expand All @@ -22,7 +24,12 @@
"email": "[email protected]",
"url": "https://staticblogs.ca/users/staticBanter"
},
"license":"GPL-3.0",
"licenses":[
{
"type": "GPL-3.0",
"url": "https://www.gnu.org/licenses/gpl-3.0.html"
}
],
"bugs": {
"url": "https://github.com/staticBanter/simplePass/issues"
},
Expand Down
File renamed without changes.
4 changes: 4 additions & 0 deletions simplePass/data/interfaces/charCodeRequest.interface.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
'use strict';
;
;
export {};
2 changes: 2 additions & 0 deletions simplePass/data/interfaces/passwordModifier.interface.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
'use strict';
export {};
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
const L_requiredAttributes = [
'lowercase',
'uppercase',
'numbers',
'punctuation',
'special',
'memorable'
'memorable',
];
export default L_requiredAttributes;
14 changes: 14 additions & 0 deletions simplePass/data/lists/usableAttributes,list.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
'use strict';
const L_useableAttributes = [
'lowercase',
'uppercase',
'numbers',
'punctuation',
'special',
'memorable',
'w_beginning',
'w_end',
'w_between',
'excludeCharacters'
];
export default L_useableAttributes;
9 changes: 9 additions & 0 deletions simplePass/data/lists/whitespaceAttributes.list.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
'use strict';
const L_whitespaceAttributes = [
'w_beginning',
'w_end',
'w_between',
'w_end_required',
'w_beginning_required',
];
export default L_whitespaceAttributes;
29 changes: 29 additions & 0 deletions simplePass/data/objects/characterCodeConstraints.object.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
'use strict';
const characterCodeConstraints = {
lowercase: {
min: 97,
max: 122,
},
uppercase: {
min: 65,
max: 90,
},
numbers: {
min: 48,
max: 57,
},
punctuation: {
min: 33,
max: 126,
range: [
[33, 47],
[58, 64],
[91, 96],
[123, 126]
]
},
whitespace: {
single: 32
},
};
export default characterCodeConstraints;
2 changes: 1 addition & 1 deletion simplePass/helpers/cleanModifier.helper.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
'use strict';
import L_allowedModifiers from "../lists/allowedModifiers.list.js";
import L_allowedModifiers from "../data/lists/allowedModifiers.list.js";
export default function cleanModifier(modifier) {
const converter = {};
if (modifier instanceof FormData) {
Expand Down
41 changes: 0 additions & 41 deletions simplePass/helpers/conformPassword.helper.js

This file was deleted.

10 changes: 10 additions & 0 deletions simplePass/helpers/createModifierList.helper.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
'use strict';
export default function createModifierList(modifier, list) {
const modifiers = [];
Object.keys(modifier).forEach((key) => {
if (list.includes(key)) {
modifiers.push(key);
}
});
return modifiers;
}
Loading

0 comments on commit 416dde3

Please sign in to comment.