Added passwordGenerator
This commit is contained in:
parent
7ebac06ee5
commit
806ceadeeb
|
@ -11,7 +11,8 @@ module.exports = {
|
||||||
},
|
},
|
||||||
|
|
||||||
parserOptions: {
|
parserOptions: {
|
||||||
parser: '@babel/eslint-parser'
|
parser: '@babel/eslint-parser',
|
||||||
|
requireConfigFile: false
|
||||||
},
|
},
|
||||||
|
|
||||||
extends: ['plugin:vue/recommended', '@vue/prettier'],
|
extends: ['plugin:vue/recommended', '@vue/prettier'],
|
||||||
|
|
|
@ -39,7 +39,7 @@
|
||||||
<script>
|
<script>
|
||||||
import UserSelect from './UserSelect'
|
import UserSelect from './UserSelect'
|
||||||
import NewPasswordFields from './NewPasswordFields'
|
import NewPasswordFields from './NewPasswordFields'
|
||||||
// import generator from 'generate-password'
|
import { passwordGenerator } from '../utils/passwordGenerator'
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: 'ReplacePasswordForm',
|
name: 'ReplacePasswordForm',
|
||||||
|
@ -69,17 +69,7 @@ export default {
|
||||||
}),
|
}),
|
||||||
methods: {
|
methods: {
|
||||||
generatePassword() {
|
generatePassword() {
|
||||||
// this.suggestion = generator.generate({
|
this.suggestion = passwordGenerator()
|
||||||
// length: 8,
|
|
||||||
// numbers: true,
|
|
||||||
// symbols: true,
|
|
||||||
// uppercase: true,
|
|
||||||
// lowercase: true,
|
|
||||||
// excludeSimilarCharacters: true,
|
|
||||||
// strict: true
|
|
||||||
// })
|
|
||||||
|
|
||||||
this.suggestion = 'ifms.123456'
|
|
||||||
},
|
},
|
||||||
|
|
||||||
defaultPassword() {
|
defaultPassword() {
|
||||||
|
|
58
web/src/utils/passwordGenerator.js
Normal file
58
web/src/utils/passwordGenerator.js
Normal file
|
@ -0,0 +1,58 @@
|
||||||
|
// Generate a random password of a given length
|
||||||
|
// containing at least one lowercase letter, one uppercase letter, one number, and one special character
|
||||||
|
export function passwordGenerator(length = 8) {
|
||||||
|
// Define character sets
|
||||||
|
const lowerCaseLetters = 'abcdefghijklmnopqrstuvwxyz'
|
||||||
|
const upperCaseLetters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
|
||||||
|
const numbers = '0123456789'
|
||||||
|
const specialCharacters = '!@#$%&*()[]{}/'
|
||||||
|
|
||||||
|
// Initialize character set
|
||||||
|
let characterSet = ''
|
||||||
|
|
||||||
|
// Initialize password
|
||||||
|
let password = ''
|
||||||
|
|
||||||
|
// Add a lowercase letter to the character set
|
||||||
|
characterSet += lowerCaseLetters
|
||||||
|
// Pick a random lowercase letter and add it to the password
|
||||||
|
password += lowerCaseLetters.charAt(
|
||||||
|
Math.floor(Math.random() * lowerCaseLetters.length)
|
||||||
|
)
|
||||||
|
|
||||||
|
// Add an uppercase letter to the character set
|
||||||
|
characterSet += upperCaseLetters
|
||||||
|
// Pick a random uppercase letter and add it to the password
|
||||||
|
password += upperCaseLetters.charAt(
|
||||||
|
Math.floor(Math.random() * upperCaseLetters.length)
|
||||||
|
)
|
||||||
|
|
||||||
|
// Add a number to the character set
|
||||||
|
characterSet += numbers
|
||||||
|
// Pick a random number and add it to the password
|
||||||
|
password += numbers.charAt(Math.floor(Math.random() * numbers.length))
|
||||||
|
|
||||||
|
// Add a special character to the character set
|
||||||
|
characterSet += specialCharacters
|
||||||
|
// Pick a random special character and add it to the password
|
||||||
|
password += specialCharacters.charAt(
|
||||||
|
Math.floor(Math.random() * specialCharacters.length)
|
||||||
|
)
|
||||||
|
|
||||||
|
// Add random characters to the password until it reaches the desired length
|
||||||
|
for (let i = 4; i < length; i++) {
|
||||||
|
password += characterSet.charAt(
|
||||||
|
Math.floor(Math.random() * characterSet.length)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Shuffle the password
|
||||||
|
password = password
|
||||||
|
.split('')
|
||||||
|
.sort(function () {
|
||||||
|
return 0.5 - Math.random()
|
||||||
|
})
|
||||||
|
.join('')
|
||||||
|
|
||||||
|
return password
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user