Skip to content

Commit

Permalink
Changed Math.Random with crypto.randomInt
Browse files Browse the repository at this point in the history
  • Loading branch information
Maheshkumar-Kakade committed Oct 17, 2021
1 parent d4a4f5b commit b27de1c
Show file tree
Hide file tree
Showing 4 changed files with 564 additions and 503 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ npm install otp-generator --save
## Usage

```js
var otpGenerator = require('otp-generator')
const otpGenerator = require('otp-generator')

otpGenerator.generate(6, { upperCase: false, specialChars: false });

Expand Down
9 changes: 3 additions & 6 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
/**
* Generate password from allowed word
*/
const crypto = require('crypto')

const digits = '0123456789'
const alphabets = 'abcdefghijklmnopqrstuvwxyz'
const upperCase = alphabets.toUpperCase()
const specialChars = '#!&@'

function rand (min, max) {
const random = Math.random()
return Math.floor(random * (max - min) + min)
}

module.exports = {
/**
* Generate OTP of the length
Expand All @@ -36,7 +33,7 @@ module.exports = {
((generateOptions.specialChars || '') && specialChars)
let password = ''
while (password.length < length) {
const charIndex = rand(0, allowsChars.length - 1)
const charIndex = crypto.randomInt(0, allowsChars.length)
password += allowsChars[charIndex]
}
return password
Expand Down
Loading

0 comments on commit b27de1c

Please sign in to comment.