Merge pull request #36179 from nextcloud/backport/36093/stable25

[stable25] Improve password generation for link shares
This commit is contained in:
Vincent Petry 2023-01-18 12:02:32 +01:00 committed by GitHub
commit b6d850d25e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 12 additions and 9 deletions

View file

@ -24,6 +24,7 @@ import axios from '@nextcloud/axios'
import Config from '../services/ConfigService'
const config = new Config()
// note: some chars removed on purpose to make them human friendly when read out
const passwordSet = 'abcdefgijkmnopqrstwxyzABCDEFGHJKLMNPQRSTWXYZ23456789'
/**
@ -46,10 +47,12 @@ export default async function() {
}
}
// generate password of 10 length based on passwordSet
return Array(10).fill(0)
.reduce((prev, curr) => {
prev += passwordSet.charAt(Math.floor(Math.random() * passwordSet.length))
return prev
}, '')
const array = new Uint8Array(10)
const ratio = passwordSet.length / 255
self.crypto.getRandomValues(array)
let password = ''
for (let i = 0; i < array.length; i++) {
password += passwordSet.charAt(array[i] * ratio)
}
return password
}

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long