Skip to content

Commit

Permalink
Merge pull request #36093 from nextcloud/techdebt/noid/improve-share-…
Browse files Browse the repository at this point in the history
…pw-generation

Improve password generation for link shares
  • Loading branch information
nickvergessen committed Jan 16, 2023
2 parents 018a597 + e9f7ea1 commit 7f81ce5
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 9 deletions.
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 @@ -25,6 +25,7 @@ import Config from '../services/ConfigService'
import { showError, showSuccess } from '@nextcloud/dialogs'

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

/**
Expand All @@ -49,10 +50,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
}
4 changes: 2 additions & 2 deletions dist/files_sharing-files_sharing_tab.js

Large diffs are not rendered by default.

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

Large diffs are not rendered by default.

0 comments on commit 7f81ce5

Please sign in to comment.