protected void GenerateOTP(object sender, EventArgs e) { // Check whether Username and Email are empty bool empty = false; if (string.IsNullOrEmpty(UserName.Text)) { UsernameValidate.Text = "required"; empty = true; } else { UsernameValidate.Text = ""; } if (string.IsNullOrEmpty(Email.Text)) { EmailValidate.Text = "required"; empty = true; } else { UsernameValidate.Text = ""; } if (empty == true) { return; } SignUpValidate.Text = ""; OtpInvalidLabel.Text = ""; // Generate OTP var Otp = GenerateOtp.Generate(); Logging.WriteLog("New user", "OTP generated"); Session["Otp"] = Otp; // Send the OTP to user e-mail if (ConfigurationManager.AppSettings["DisableMail"] == "true") { ScriptManager.RegisterClientScriptBlock(Page, typeof(Page), "ClientScript", "alert('This feature is disabled. Use " + Otp + " as OTP')", true); return; } bool otp_sent = Mail.SendVerificationMail(Otp, Email.Text); if (otp_sent == true) { OtpInvalidLabel.Text = "OTP is sent to your email"; Logging.WriteLog("New user", "OTP sent to mail"); } else { OtpInvalidLabel.Text = "Unable to send OTP. Enter valid email ID or try after some time"; } }
protected void GenerateOTP(object sender, EventArgs e) { // Disable if redirected after resetting password if (Session["forget"].ToString() == "true") { ScriptManager.RegisterClientScriptBlock(Page, typeof(Page), "ClientScript", "alert('Change your password')", true); return; } // Clear all labels ClearText(); bool empty = CheckProfileEmpty(); if (empty == true) { return; } // Generate OTP Session["Otp"] = GenerateOtp.Generate(); Logging.WriteLog(Session["UserName"].ToString(), "OTP generated"); // Send the OTP to user e-mail if (ConfigurationManager.AppSettings["DisableMail"] == "true") { ScriptManager.RegisterClientScriptBlock(Page, typeof(Page), "ClientScript", "alert('This feature is disabled. Use " + Session["Otp"].ToString() + " as OTP')", true); //OtpValidate.Text = "This feature is disabled. Use " + Session["Otp"].ToString() + " as OTP"; return; } bool otp_sent = Mail.SendVerificationMail(Session["Otp"].ToString(), Email.Text); if (otp_sent == true) { OtpValidate.Text = "OTP is sent to your email"; Logging.WriteLog(Session["UserName"].ToString(), "OTP sent to mail"); } else { OtpValidate.Text = "Unable to send OTP. Enter valid email ID or try after some time"; } }