Skip to content
Snippets Groups Projects
Commit 62c2f7b3 authored by Aaron Dötsch's avatar Aaron Dötsch
Browse files

Shorten bulk voucher default length

When bulk creating vouchers it was using a code length of 14 characters. Doing the math
shows that with just 6 characters of length you need more than 33 thousand codes in
order to have a 1% chance of collision (assuming I was using that online calculator
correctly). That's more than enough.
parent 270d9ed2
No related branches found
No related tags found
No related merge requests found
...@@ -109,7 +109,8 @@ export async function editVoucher(id, code, amount, activated, expiresAt){ ...@@ -109,7 +109,8 @@ export async function editVoucher(id, code, amount, activated, expiresAt){
}); });
} }
function generateRandomString(forbidden=new Set(), length=14, chars="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"){ // >33k codes needed for a 1% chance of a collision
function generateRandomString(forbidden=new Set(), length=6, chars="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"){
let result = ""; let result = "";
for(let i = 0; i < length; i++){ for(let i = 0; i < length; i++){
result += chars.charAt(Math.floor(Math.random() * chars.length)); result += chars.charAt(Math.floor(Math.random() * chars.length));
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment