random-passwords-generator
v1.0.5
Published
A npm package that helps you generate random passwords by passing in a criteria.
Downloads
3
Maintainers
Readme
random-passwords-generator
Random passwords generator is used to generate passwords that may contain alphabets, number and special characters. The options parameter enables the user to enable or disabe the characters that are used to generate the password. The characters that may be choosen from are
- Lowercase Characters
- Uppercase Characters
- Numbers
- Special characters
The user may also opt to choose the first character in the password. The first character may one of the below.
- Lowercase Character
- Uppercase Character
- Number
- Special Character
The user may also specify the minimum number of character of each type.
Installation
npm install random-passwords-generator
Usage
For the password to be generated, PARAMETERS should be passed as an optional options object.
If no parameter is passed, the default parameter will be taken as :
options = {
LENGTH: 10,
ALLOW_ALPHABETS_LOWERCASE: true,
ALLOW_ALPHABETS_UPPERCASE: true,
ALLOW_NUMBERS: true,
ALLOW_SPECIAL_CHARACTERS: true,
EXCEPTIONS: "",
FIRST_CHARACTER_LOWERCASE: true,
FIRST_CHARACTER_UPPERCASE: false,
FIRST_CHARACTER_NUMBER: false,
FIRST_CHARACTER_SPECIAL_CHARACTER: false,
MIN_ALPHABETS_LOWERCASE: 1,
MIN_ALPHABETS_UPPERCASE: 1,
MIN_NUMBERS: 1,
MIN_SPECIAL_CHARACTERS: 1,
};
The parameters are
LENGTH : the length of the password to be generated. Default Value : 10.
ALLOW_ALPHABETS_LOWERCASE : can take a boolean value that decides whether the password can have lowecase alphabets. Default Value : true.
ALLOW_ALPHABETS_UPPERCASE : can take a boolean value of true or false. If true, the password generated can have uppercase characters. Default Value : false.
ALLOW_NUMBERS: : option can take a boolean which decides wherher the password generated can have numbers.
ALLOW_SPECIAL_CHARACTERS : option accepts boolean value and decides whether the password generated can have special characters. The special characters are : !#$%&'()+,-./:;<=>?@[]^_`{|}~*
EXCEPTIONS : exception takes in a string of characters that would not be used to generate the password. If "abc" is passed as exceptions, then the password willnot have the characters a,b,c
FIRST_CHARACTER_LOWERCASE - only if ALLOW_ALPHABETS_LOWERCASE is set to true, FIRST_CHARACTER_LOWERCASE will create a password that will have the first character as a lowercase character. Default value is true.
FIRST_CHARACTER_UPPERCASE - only if ALLOW_ALPHABETS_UPPERCASE is set to true, FIRST_CHARACTER_UPPERCASE will create a password that will have the first character as uppercase. Default value is false.
FIRST_CHARACTER_NUMBER - only if ALLOW_NUMBERS is set to true, FIRST_CHARACTER_NUMBER will create a password that will have the first character as number. Default value is false.
FIRST_CHARACTER_SPECIAL_CHARACTER - only if ALLOW_SPECIAL_CHARACTERS is set to true, FIRST_CHARACTER_SPECIAL_CHARACTER will create a password that will have the first character as special character. Default value is false.
MIN_ALPHABETS_LOWERCASE - only if ALLOW_ALPHABETS_LOWERCASE is set to true, MIN_ALPHABETS_LOWERCASE will create a password that will have minimum number of lower case characters in the password. Default value is 1.
MIN_ALPHABETS_UPPERCASE - only if ALLOW_ALPHABETS_UPPERCASE is set to true, MIN_ALPHABETS_UPPERCASE will create a password that will have minimum number of upper case characters in the password. Default value is 1.
MIN_NUMBERS - only if ALLOW_NUMBERS is set to true, MIN_NUMBERS will create a password that will have minimum number of numbers in the password. Default value is 1.
MIN_SPECIAL_CHARACTERS - only if ALLOW_SPECIAL_CHARACTERS is set to true, MIN_SPECIAL_CHARACTERS will create a password that will have minimum number of special characters in the password. Default value is 1.
Example
- No Options passed.
const passwords = require("random-passwords-generator");
password = passwords();
console.log(password);
In the above case, no parameter is passed as option. Therefore the default values will be taken - which will have alphabets, both upper and lower case, special characters and will be of length 10 characters.
j8GGa3Udr8
- Length parameter passed.
options={
LENGTH : 25;
}
password = passwords(options);
console.log(password);
The password generated is
t4eWL36LxL=h-cnqirU,T841l
- Only Characters(Lower and Upper) Password - Without Numbers and Special Characters
options = {
LENGTH: 25,
ALLOW_ALPHABETS_LOWERCASE: true,
ALLOW_ALPHABETS_UPPERCASE: true,
ALLOW_NUMBERS: false,
ALLOW_SPECIAL_CHARACTERS: false,
EXCEPTIONS: "",
FIRST_CHARACTER_LOWERCASE: true,
FIRST_CHARACTER_UPPERCASE: false,
FIRST_CHARACTER_NUMBER: false,
FIRST_CHARACTER_SPECIAL_CHARACTER: false,
MIN_ALPHABETS_LOWERCASE: 1,
MIN_ALPHABETS_UPPERCASE: 1,
MIN_NUMBERS: 1,
MIN_SPECIAL_CHARACTERS: 1,
};
passwords = password(options);
console.log(passwords);
In the above case, the password generated will have alphabets, both lower and uppercase and will not have numbers and special characters.
gjjmvsxiqVTiPRwbzcHVGGHTM
- Only Numbers(Lower and Upper) Password - Without Alphabets (Lower and Upper) and Special Characters
options = {
LENGTH: 25,
ALLOW_ALPHABETS_LOWERCASE: false,
ALLOW_ALPHABETS_UPPERCASE: false,
ALLOW_NUMBERS: true,
ALLOW_SPECIAL_CHARACTERS: false,
EXCEPTIONS: "",
FIRST_CHARACTER_LOWERCASE: true,
FIRST_CHARACTER_UPPERCASE: false,
FIRST_CHARACTER_NUMBER: false,
FIRST_CHARACTER_SPECIAL_CHARACTER: false,
MIN_ALPHABETS_LOWERCASE: 1,
MIN_ALPHABETS_UPPERCASE: 1,
MIN_NUMBERS: 1,
MIN_SPECIAL_CHARACTERS: 1
};
passwords = password(options);
console.log(passwords);
The password will contain numbers only without any characters or special characters.
3823264088081960859802441
- Only Special Characters Password - Without Alphabets (Lower and Upper) and Numbers
options = {
LENGTH: 25,
ALLOW_ALPHABETS_LOWERCASE: false,
ALLOW_ALPHABETS_UPPERCASE: false,
ALLOW_NUMBERS: false,
ALLOW_SPECIAL_CHARACTERS: true,
EXCEPTIONS: "",
FIRST_CHARACTER_LOWERCASE: true,
FIRST_CHARACTER_UPPERCASE: false,
FIRST_CHARACTER_NUMBER: false,
FIRST_CHARACTER_SPECIAL_CHARACTER: false,
MIN_ALPHABETS_LOWERCASE: 1,
MIN_ALPHABETS_UPPERCASE: 1,
MIN_NUMBERS: 1,
MIN_SPECIAL_CHARACTERS: 1
};
passwords = password(options);
console.log(passwords);
The password will contain numbers only without any characters or special characters.
*,._>_.-<)-(&|>_#.,&(*|#;
- Minimum number of characters. Password of length 10 - 9 characters lowercase and 1 character uppercase
options = {
LENGTH: 10,
ALLOW_ALPHABETS_LOWERCASE: true,
ALLOW_ALPHABETS_UPPERCASE: true,
ALLOW_NUMBERS: false,
ALLOW_SPECIAL_CHARACTERS: false,
EXCEPTIONS: "",
FIRST_CHARACTER_LOWERCASE: true,
FIRST_CHARACTER_UPPERCASE: false,
FIRST_CHARACTER_NUMBER: false,
FIRST_CHARACTER_SPECIAL_CHARACTER: false,
MIN_ALPHABETS_LOWERCASE: 9,
MIN_ALPHABETS_UPPERCASE: 1,
MIN_NUMBERS: 1,
MIN_SPECIAL_CHARACTERS: 1
};
passwords = password(options);
console.log(passwords);
The password will contain numbers only without any characters or special characters.
pXhusaahuq
The options can be altered as per the requirement to generate the required password of required strength and complexity.
NOTE : If values are not assigned to the options, then the default values will be taken.
License
Copyright (c) 2020 Nixon Augustine
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.