summaryrefslogtreecommitdiffstats
path: root/apps/files_sharing
diff options
context:
space:
mode:
authorVincent Petry <vincent@nextcloud.com>2023-01-18 12:03:53 +0100
committerGitHub <noreply@github.com>2023-01-18 12:03:53 +0100
commit05475e32df356907740134ee1bfeda8d26686e90 (patch)
tree1a1646bd63e28c8c5e0b6c8f848dbacc0fd0a671 /apps/files_sharing
parent53f0ee12b4714b977449ddecaaa768b49b6d1dc4 (diff)
parent2246c894ad7336fc89cbf63a97a239d983c29edd (diff)
downloadnextcloud-server-05475e32df356907740134ee1bfeda8d26686e90.tar.gz
nextcloud-server-05475e32df356907740134ee1bfeda8d26686e90.zip
Merge pull request #36181 from nextcloud/backport/36093/stable24
[stable24] Improve password generation for link shares
Diffstat (limited to 'apps/files_sharing')
-rw-r--r--apps/files_sharing/src/utils/GeneratePassword.js15
1 files changed, 9 insertions, 6 deletions
diff --git a/apps/files_sharing/src/utils/GeneratePassword.js b/apps/files_sharing/src/utils/GeneratePassword.js
index f3122de1644..c7012a91274 100644
--- a/apps/files_sharing/src/utils/GeneratePassword.js
+++ b/apps/files_sharing/src/utils/GeneratePassword.js
@@ -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
}