コード例 #1
0
        /// <summary>
        /// Resends an OTP message.
        /// If there is a current OTP, then the same OTP is resent.
        /// Otherwise a new OTP is generated and sent.
        /// </summary>
        /// <param name="userId">Id of the recipient user.</param>
        /// <param name="phoneNumber">Phone number to send OTP to.</param>
        /// <param name="userType">The user type.</param>
        public static void ResendOTP(int userId, string phoneNumber, string userType)
        {
            OneTimePwd otp       = null;
            string     otpString = string.Empty;

            using (OneTimePwdDao dao = new OneTimePwdDao())
            {
                ReapOldOTPs(dao);
                otp = dao.FindByUserId(userId); // Check if there is a current OTP for the user.
                if (otp != null)                // If there is, just reset the timestamp on the OTP
                {
                    otpString       = otp.Otg;
                    otp.CreatedDate = DateTime.Now;
                    dao.Update(otp);
                }
                else
                {
                    otpString = GenerateOTP();
                    otp       = new OneTimePwd {
                        Otg = otpString, UserID = userId, UserType = userType, CreatedDate = DateTime.Now
                    };
                    dao.Insert(otp);
                }
            }
            SendOTP(phoneNumber, otpString);
        }
コード例 #2
0
 public static void RemoveOTP(int user_id, string otp_code)
 {
     using (OneTimePwdDao dao = new OneTimePwdDao())
     {
         ReapOldOTPs(dao);
         OneTimePwd otp = dao.FindByUserId(user_id);
         if (otp != null && otp.Otg == otp_code)
         {
             dao.DeleteOTP(otp);
         }
     }
 }
コード例 #3
0
 public static bool ValidateOTP(int user_id, string otp_code)
 {
     //if (otp_code == "1111")//TODO : comment out this block; only for testing
     //{
     //    return true;
     //}
     using (OneTimePwdDao dao = new OneTimePwdDao())
     {
         ReapOldOTPs(dao);
         OneTimePwd otp = dao.FindByUserId(user_id);
         if (otp != null && otp.Otg == otp_code)
         {
             return(true);
         }
     }
     return(false);
 }