Skip to content

Commit 29eb678

Browse files
authored
Merge pull request #36212 from nextcloud/techdebt/noid/improve-share-pw-generation/stable23
[stable23] Improve password generation for link shares
2 parents 2cf8353 + 3a3f7eb commit 29eb678

File tree

3 files changed

+11
-8
lines changed

3 files changed

+11
-8
lines changed

apps/files_sharing/js/dist/files_sharing_tab.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

apps/files_sharing/js/dist/files_sharing_tab.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

apps/files_sharing/src/utils/GeneratePassword.js

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import axios from '@nextcloud/axios'
2424
import Config from '../services/ConfigService'
2525

2626
const config = new Config()
27+
// note: some chars removed on purpose to make them human friendly when read out
2728
const passwordSet = 'abcdefgijkmnopqrstwxyzABCDEFGHJKLMNPQRSTWXYZ23456789'
2829

2930
/**
@@ -46,10 +47,12 @@ export default async function() {
4647
}
4748
}
4849

49-
// generate password of 10 length based on passwordSet
50-
return Array(10).fill(0)
51-
.reduce((prev, curr) => {
52-
prev += passwordSet.charAt(Math.floor(Math.random() * passwordSet.length))
53-
return prev
54-
}, '')
50+
const array = new Uint8Array(10)
51+
const ratio = passwordSet.length / 255
52+
self.crypto.getRandomValues(array)
53+
let password = ''
54+
for (let i = 0; i < array.length; i++) {
55+
password += passwordSet.charAt(array[i] * ratio)
56+
}
57+
return password
5558
}

0 commit comments

Comments
 (0)