public static async Task <GeneralResponse> ProcessGenerateOTPRequest(OTPRequest _req, OTPEmailSender sender, DBContext _dBContext) { OTPRequest _otpReq = _req; GeneralResponse _resp = null; //write request to queue. //string _msg = JsonConvert.SerializeObject(_req); //Generate OTP here _req._reqid = UniqueCodeGenerator.GetUniqueCodeForRequest(); _req._emailotp = GenerateOTP(); _req._mobileotpCode = GenerateOTP(); _req.ParkDB = _dBContext; DBParams param1 = new DBParams(); param1.FieldName = "fsReqId"; param1.FieldValue = _req._reqid; DBParams param2 = new DBParams(); param2.FieldName = "fsMobileNo"; param2.FieldValue = _req.Mobile; DBParams param3 = new DBParams(); param3.FieldName = "fsEmail"; param3.FieldValue = _req.Email; DBParams param4 = new DBParams(); param4.FieldName = "fsMobileOTP"; param4.FieldValue = _req._mobileotpCode; DBParams param5 = new DBParams(); param5.FieldName = "fsEmailOTP"; param5.FieldValue = _req._emailotp; int _retCode = await _req.InsertAsync(param1, param2, param3, param4, param5); #if DIRECTMAIL EmailMessage _message = new EmailMessage(); _message.To = _req.Email; _message.Subject = "Account Activatio Code from StarParkz"; _message.Body = _req._emailotp; await sender.SendEmailAsync(_message); #endif //QM.WriteStringToQueue(_msg); //var t = Task.Run(() => _resp = new GeneralResponseMsg() { RespCode = (int)RESPONSE.OTPRESPONSE, RespMsg = PREDEFINEDMESSAGE.MOBILE_OTP_GENERATED, Data = "OK" }); //t.Wait(); return(_resp); //validation to check if user exist or not. If exist return message that user already exist else proceed with OTP generation. //we are going to write the code to generate the OTP. // User the API to send the otp to the mobile number // also save the OTP in the database against mobile number. There has to be a time also for OTP expiration. //throw new Exception("Error"); }
public void GetUniqueCode_1_million_UniqueCodeGenerator() { var codes = new HashSet <string>(); for (int i = 0; i < million; i++) { var guid = UniqueCodeGenerator.GetUniqueCode(); Console.Write($"{guid}, "); if (!codes.Add(guid)) { Assert.Fail("UniqueCodeGeneratior duplicate found"); } } }