Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Improve password generation for link shares
Use web crypto when generating password for link shares
whenever the password policy app is disabled.

Signed-off-by: Vincent Petry <[email protected]>
Signed-off-by: nextcloud-command <[email protected]>
  • Loading branch information
PVince81 committed Jan 18, 2023
commit 3a3f7eb6969a61dd90c19f7b591c99c260af0838
2 changes: 1 addition & 1 deletion apps/files_sharing/js/dist/files_sharing_tab.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion apps/files_sharing/js/dist/files_sharing_tab.js.map

Large diffs are not rendered by default.

15 changes: 9 additions & 6 deletions apps/files_sharing/src/utils/GeneratePassword.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'

/**
Expand All @@ -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
}