Exemple #1
0
        public static string GetCurrentAccountToken(long accountId)
        {
            int responseStatus = -99;
            var par            = OtpDAO.GenerateCounter(accountId, out responseStatus);

            return(par?.AppT);
        }
Exemple #2
0
        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()));
            }
        }