public static bool ValidateOTP(long accountId, string otp, string phonenumber = "") { if (string.IsNullOrEmpty(phonenumber)) { phonenumber = string.Empty; } var ct = OtpDAO.GetCurrentCounter(accountId); if (ct == null || string.IsNullOrEmpty(ct.T)) { return(false); } bool valid = false; NLogManager.LogMessage(GetTimeOTP(ct.T + "_" + phonenumber, ct.C + GetCurrentCounter()) + "|" + otp + "|" + phonenumber + "|" + accountId + "|" + ct.C + "|" + (ct.C + GetCurrentCounter())); if (!string.IsNullOrEmpty(phonenumber)) { valid = GetTimeOTP(ct.T + "_" + phonenumber, ct.C + GetCurrentCounter()) == otp; if (!valid) { valid = GetTimeOTP(ct.T + "_" + phonenumber, ct.C - 1 + GetCurrentCounter()) == otp; } } else { valid = GetTimeOTP(ct.AppT + "_" + phonenumber, ct.C + GetCurrentCounter()) == otp; if (!valid) { valid = GetTimeOTP(ct.AppT + "_" + phonenumber, ct.C - 1 + GetCurrentCounter()) == otp; } } NLogManager.LogMessage("ValidateOTP: " + valid); return(valid); }
public static string GetCurrentAccountToken(long accountId) { int responseStatus = -99; var par = OtpDAO.GenerateCounter(accountId, out responseStatus); return(par?.AppT); }
public static string GenerateOTP(long accountId, string phonenumber = "") { OTPError err = null; if (!string.IsNullOrEmpty(phonenumber)) { if (_cache.TryGetValue(accountId, out err)) { if (!err.CanGet) { if (DateTime.Now.Subtract(err.LastTime).TotalMinutes <= 2) { return("-70"); } err.LastTime = DateTime.Now; err.CanGet = true; } else { err.CanGet = true; err.LastTime = DateTime.Now; } } if (err == null) { err = new OTPError { CanGet = true, LastTime = DateTime.Now }; _cache.AddOrUpdate(accountId, err, (k, v) => err); } } if (string.IsNullOrEmpty(phonenumber)) { phonenumber = string.Empty; } int responseStatus = -99; var ct = OtpDAO.GenerateCounter(accountId, out responseStatus); NLogManager.LogMessage(accountId + "|" + phonenumber + "|" + ct.C + "|" + (ct.C + GetCurrentCounter())); if (!string.IsNullOrEmpty(phonenumber)) { err.CanGet = false; return(GetTimeOTP(ct.T + "_" + phonenumber, ct.C + GetCurrentCounter())); } else { return(GetTimeOTP(ct.AppT + "_" + phonenumber, ct.C + GetCurrentCounter())); } }
public static void SetToken(long accountId, string deviceToken) { OtpDAO.SetToken(accountId, deviceToken); }