Skip to content

Commit b6d850d

Browse files
authored
Merge pull request #36179 from nextcloud/backport/36093/stable25
[stable25] Improve password generation for link shares
2 parents d2070bd + 2aad203 commit b6d850d

3 files changed

Lines changed: 12 additions & 9 deletions

File tree

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
}

dist/files_sharing-files_sharing_tab.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/files_sharing-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.

0 commit comments

Comments
 (0)