Skip to content

Commit

Permalink
Make generated passwords longer (#14362)
Browse files Browse the repository at this point in the history
* Make generated passwords longer

* Use crypto for generating passwords

* Remove comments

* Generate password with length 12
  • Loading branch information
melohagan authored Aug 12, 2024
1 parent d0f1dc2 commit 151fff5
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
export let showOnboardingTypeModal
const password = Math.random().toString(36).substring(2, 22)
const password = generatePassword(12)
let disabled
let userGroups = []
Expand Down Expand Up @@ -44,7 +44,7 @@
{
email: "",
role: "appUser",
password: Math.random().toString(36).substring(2, 22),
password: generatePassword(12),
forceResetPassword: true,
error: null,
},
Expand All @@ -69,6 +69,14 @@
return userData[index].error == null
}
function generatePassword(length) {
const array = new Uint8Array(length)
window.crypto.getRandomValues(array)
return Array.from(array, byte => byte.toString(36).padStart(2, "0"))
.join("")
.slice(0, length)
}
const onConfirm = () => {
let valid = true
userData.forEach((input, index) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@
const newUser = {
email: email,
role: usersRole,
password: Math.random().toString(36).substring(2, 22),
password: generatePassword(12),
forceResetPassword: true,
}
Expand Down Expand Up @@ -288,6 +288,14 @@
}
}
const generatePassword = length => {
const array = new Uint8Array(length)
window.crypto.getRandomValues(array)
return Array.from(array, byte => byte.toString(36).padStart(2, "0"))
.join("")
.slice(0, length)
}
onMount(async () => {
try {
await groups.actions.init()
Expand Down
10 changes: 9 additions & 1 deletion packages/worker/src/api/controllers/global/users.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,14 @@ import { BpmStatusKey, BpmStatusValue } from "@budibase/shared-core"

const MAX_USERS_UPLOAD_LIMIT = 1000

const generatePassword = (length: number) => {
const array = new Uint8Array(length)
crypto.getRandomValues(array)
return Array.from(array, byte => byte.toString(36).padStart(2, "0"))
.join("")
.slice(0, length)
}

export const save = async (ctx: UserCtx<User, SaveUserResponse>) => {
try {
const currentUserId = ctx.user?._id
Expand Down Expand Up @@ -296,7 +304,7 @@ export const onboardUsers = async (

let createdPasswords: Record<string, string> = {}
const users: User[] = ctx.request.body.map(invite => {
let password = Math.random().toString(36).substring(2, 22)
const password = generatePassword(12)
createdPasswords[invite.email] = password

return {
Expand Down

0 comments on commit 151fff5

Please sign in to comment.