From 658e93c6ee055585e33fee05d05ada64a4798d55 Mon Sep 17 00:00:00 2001 From: tokslaw7 Date: Sun, 4 Feb 2024 23:47:30 +0000 Subject: [PATCH] PIN generation code --- wrenchboard/src/shared_tool/family_acc.cc | 32 +++++++++++++++++++---- 1 file changed, 27 insertions(+), 5 deletions(-) diff --git a/wrenchboard/src/shared_tool/family_acc.cc b/wrenchboard/src/shared_tool/family_acc.cc index a1958bea..2a427516 100644 --- a/wrenchboard/src/shared_tool/family_acc.cc +++ b/wrenchboard/src/shared_tool/family_acc.cc @@ -6,6 +6,8 @@ #include "email.h" #include "safestring.h" #include +#include +#include #include "pgsql.h" #include "pgsql_wrapper.h" #include @@ -1156,9 +1158,26 @@ wrenchboard=> select * from members_family; return ret; } +/* WARNING: Unsafe function without buffer length check! */ +void GeneratePIN(int length, char *buffer) { + if (length < 2) { + sprintf(buffer, "%d", rand() % 10); // if the PIN length is less than 2 - make a single digit + return; + } + // leading number must not be 0 + long long randomNumber = (rand() % 9) + 1; + const int n = length - 1; + for (int i = 0; i