Esempio n. 1
0
        public static MobileHash Create(DataSource ds, long mobile, int type, int timespan)
        {
            MobileHash hash = Db <MobileHash> .Query(ds)
                              .Select()
                              .Where(W("Type", type) & W("Mobile", mobile))
                              .First <MobileHash>();

            if (hash != null)
            {
                if (hash.CreationDate.AddSeconds(timespan) > DateTime.Now)
                {
                    return(null);
                }
                hash.Hash         = RndHash();
                hash.CreationDate = DateTime.Now;
                if (hash.Update(ds) == DataStatus.Success)
                {
                    return(hash);
                }
            }
            else
            {
                hash = new MobileHash()
                {
                    Mobile = mobile, Type = type, Hash = RndHash(), CreationDate = DateTime.Now
                };
                if (hash.Insert(ds) == DataStatus.Success)
                {
                    return(hash);
                }
            }
            return(null);
        }
Esempio n. 2
0
        public static bool Equals(DataSource ds, long mobile, int type, string hash)
        {
            if (!mobile.IsMobile() || string.IsNullOrEmpty(hash))
            {
                return(false);
            }
            MobileHash mh = ExecuteSingleRow <MobileHash>(ds, P("Type", type) & P("Mobile", mobile));

            if (mh == null)
            {
                return(false);
            }
            if (!string.Equals(mh.Hash, hash, StringComparison.OrdinalIgnoreCase))
            {
                return(false);
            }
            SMSCaptchaSection section = SMSCaptchaSection.GetSection();

            if (section.Expiration > 0 && mh.CreationDate.AddSeconds(section.Expiration) < DateTime.Now)
            {
                return(false);
            }
            mh.Hash         = string.Empty;
            mh.CreationDate = (DateTime)Types.GetDefaultValue(TType <DateTime> .Type);
            mh.Update(ds);
            return(true);
        }