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
21 changes: 20 additions & 1 deletion apps/files_sharing/src/utils/GeneratePassword.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,29 @@ export default async function(verbose = false): Promise<string> {

const array = new Uint8Array(10)
const ratio = passwordSet.length / 255
self.crypto.getRandomValues(array)
getRandomValues(array)
let password = ''
for (let i = 0; i < array.length; i++) {
password += passwordSet.charAt(array[i] * ratio)
}
return password
}

/**
* Fills the given array with cryptographically secure random values.
* If the crypto API is not available, it falls back to less secure Math.random().
* Crypto API is available in modern browsers on secure contexts (HTTPS).
*
* @param {Uint8Array} array - The array to fill with random values.
*/
function getRandomValues(array: Uint8Array): void {
if (self?.crypto?.getRandomValues) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (self?.crypto?.getRandomValues) {
if (self.crypto?.getRandomValues) {

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Eehehe I thought self could also be undefined sometimes 🤭🤭
I guess we're adamant this is the browser anyway so yeah, maybe not needed 😊

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you expect self to be undefined, then just use globalThis instead ;)

self.crypto.getRandomValues(array)
return
}

let len = array.length
while (len--) {
array[len] = Math.floor(Math.random() * 256)
}
}
4 changes: 2 additions & 2 deletions dist/519-519.js

Large diffs are not rendered by default.

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

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions dist/5792-5792.js

Large diffs are not rendered by default.

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

Large diffs are not rendered by default.

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.

4 changes: 2 additions & 2 deletions dist/files_sharing-init.js

Large diffs are not rendered by default.

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

Large diffs are not rendered by default.

Loading