From 0d518c15a560169cf1dcf6159506f62509c5aaf0 Mon Sep 17 00:00:00 2001 From: tokslaw7 Date: Sun, 6 Aug 2023 03:39:33 +0000 Subject: [PATCH] PIN generator --- wrenchboard/src/shared_tool/account.cc | 28 +++++++++++++------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/wrenchboard/src/shared_tool/account.cc b/wrenchboard/src/shared_tool/account.cc index 41044c65..e2a8892e 100644 --- a/wrenchboard/src/shared_tool/account.cc +++ b/wrenchboard/src/shared_tool/account.cc @@ -1085,6 +1085,17 @@ long WrenchLoadDashData(CVars in, CVars &out) { return ret; } +char *pin_generator(char *pin, int pin_length) { + int base_number = 10; + srand(time(0)); + for(int i = 0; i < pin_length; i++) + { + const char ch = 48 + (rand() % base_number); + *(pin+i) = (char)ch; + } + return pin; +} + long WrenchResetMemberPass(CVars in, CVars &out) { logfmt(logINFO, "long WrenchResetMemberPass(CVars in, CVars out)"); long ret = PHP_API_BAD_PARAM; @@ -1098,20 +1109,9 @@ long WrenchResetMemberPass(CVars in, CVars &out) { member_id = yy["member_id"].Long(); } - int r1, i; - char reset_pin[10]; - srand(time(NULL)); - r1 = abs(rand()*100); -// sprintf(reset_pin, "%d", r1); - - snprintf(reset_pin, sizeof (reset_pin), "%d", r1); // I am trying to generate 4 or 5 digits random numbers here - -// for (i = 1; i <5; i++) -// { -// srand(time(NULL)); -// r1 = abs(rand()); -// sprintf(reset_pin, "%d", r1); -// } + char reset_pin[10]; // Please make sure there is enough space to hold the generated pin or you will get a "Segmentation fault" crash + bzero(reset_pin, sizeof (reset_pin)); // Make it clean with zeroes or you likely to get a "Segmentation fault" crash on dirty RAM + pin_generator(reset_pin, 5); // I am trying to generate 4 or 5 digits random numbers here CVars xx; if (member_id > 0) {