public Authentication(string tel, string password)
 {
     if (string.IsNullOrEmpty(tel) || string.IsNullOrEmpty(password))
     {
         state = "缺少请求参数";
         return;
     }
     password = CommonSecurity.SHA1MD5MD5(password);
     using (Entity entity = new Entity())
     {
         var user = entity.User.Where(o => o.Tel == tel && o.PassWord == password).FirstOrDefault();
         if (user == null)
         {
             state = "用户名或密码不对";
             return;
         }
         if (user.State == 0)
         {
             state = "该用户已经冻结";
             return;
         }
         this.userID = user.UserID;
         this.time   = CommonTime.GetTimeStamp();
         string source = this.userID + "^" + this.time + "^" + seed;
         this.token    = CommonSecurity.SHA1(source);
         this.userType = user.Type;
     }
 }
        public Authentication(HttpRequestBase request)
        {
            string token  = request["authentication_token"];
            string userID = request["authentication_userID"];
            string time   = request["authentication_time"];

            if (string.IsNullOrEmpty(userID) || string.IsNullOrEmpty(time) || string.IsNullOrEmpty(token))
            {
                state = "缺少请求参数";
                return;
            }
            if (!int.TryParse(userID, out this.userID))
            {
                state = "用户ID不正确";
                return;
            }
            this.time  = time;
            this.token = token;
            string source = userID + "^" + time + "^" + seed;

            if (token != CommonSecurity.SHA1(source))
            {
                state = "登陆失败";
                return;
            }
        }
Esempio n. 3
0
        public string chongzhimima(string tel, string password, string yanzhengma)
        {
            if (tel == null)
            {
                return("{error:'电话号码不能为空'}");
            }
            if (yanzhengma == null)
            {
                return("{error:'验证码不能为空'}");
            }

            string pattern = @"^(0|86|17951)?(1[234578])[0-9]{9}$";
            Regex  rgx     = new Regex(pattern);

            if (!rgx.IsMatch(tel))
            {
                return("{error:'电话号不正确'}");
            }
            if (password == null)
            {
                return("{error:'密码不能为空'}");
            }
            if (password.Length < 6)
            {
                return("{error:'密码长度不能小于6'}");
            }

            using (Entity entity = new Entity())
            {
                UserSMS userSMS = entity.UserSMS
                                  .Where(o => o.Tel == tel && o.State == 0)
                                  .OrderByDescending(o => o.SentTime)
                                  .FirstOrDefault();
                if (userSMS == null)
                {
                    return("{error:'验证码不正确'}");
                }
                User user = entity.User
                            .Where(o => o.Tel == tel)
                            .FirstOrDefault();
                if (user == null)
                {
                    return("{error:'账号不存在'}");
                }

                string passwordTemp = CommonSecurity.SHA1MD5MD5(password);
                user.PassWord = passwordTemp;
                userSMS.State = 1;
                entity.SaveChanges();
                Authentication authentication = new Authentication(user.Tel, password);
                return(authentication.tokenUserTime());
            }
        }
Esempio n. 4
0
        public string login(string tel, string password)
        {
            if (tel == null)
            {
                return("{error:'电话号码不能为空'}");
            }
            string pattern = @"^(0|86|17951)?(1[234578])[0-9]{9}$";
            Regex  rgx     = new Regex(pattern);

            if (!rgx.IsMatch(tel))
            {
                return("{error:'电话号不正确'}");
            }
            if (password == null)
            {
                return("{error:'密码不能为空'}");
            }
            if (password.Length < 6)
            {
                return("{error:'密码长度不能小于6'}");
            }
            string passwordTemp = CommonSecurity.SHA1MD5MD5(password);

            using (Entity entity = new Entity())
            {
                User user = entity.User
                            .Where(o => o.Tel == tel && o.PassWord == passwordTemp)
                            .FirstOrDefault();
                if (user == null)
                {
                    return("{error:'账号或密码不正确'}");
                }

                Authentication authentication = new Authentication(user.Tel, password);
                if (!string.IsNullOrEmpty(authentication.state))
                {
                    return("{error:'" + authentication.state + "'}");
                }
                return(authentication.tokenUserTime());
            }
        }
        public Authentication(string userID, string time, string token)
        {
            if (string.IsNullOrEmpty(userID) || string.IsNullOrEmpty(time) || string.IsNullOrEmpty(token))
            {
                state = "缺少请求参数";
                return;
            }
            if (!int.TryParse(userID, out this.userID))
            {
                state = "用户ID不正确";
                return;
            }
            this.time  = time;
            this.token = token;
            string source = userID + "^" + time + "^" + seed;

            if (token != CommonSecurity.SHA1(source))
            {
                throw new Exception();
            }
        }
Esempio n. 6
0
        public string regist(string tel, string password, string yanzhengma, string xingbie)
        {
            if (tel == null)
            {
                return("{error:'电话号码不能为空'}");
            }
            if (yanzhengma == null)
            {
                return("{error:'验证码不能为空'}");
            }
            if (xingbie == null || (xingbie != "男" && xingbie != "女"))
            {
                return("{error:'性别不正确'}");
            }
            string pattern = @"^(0|86|17951)?(1[234578])[0-9]{9}$";
            Regex  rgx     = new Regex(pattern);

            if (!rgx.IsMatch(tel))
            {
                return("{error:'电话号不正确'}");
            }
            if (password == null)
            {
                return("{error:'密码不能为空'}");
            }
            if (password.Length < 6)
            {
                return("{error:'密码长度不能小于6'}");
            }

            using (Entity entity = new Entity())
            {
                UserSMS userSMS = entity.UserSMS
                                  .Where(o => o.Tel == tel && o.State == 0)
                                  .OrderByDescending(o => o.SentTime)
                                  .FirstOrDefault();

                if (userSMS == null)
                {
                    return("{error:'验证码不正确'}");
                }
                if (entity.User.Where(o => o.Tel == tel).Count() > 0)
                {
                    return("{error:'用户已经存在'}");
                }
                string passwordTemp = CommonSecurity.SHA1MD5MD5(password);
                User   user         = new User()
                {
                    Tel        = tel,
                    PassWord   = passwordTemp,
                    NickName   = "分享玩家",
                    CreatTime  = DateTime.Now,
                    UpdateTime = DateTime.Now,
                    State      = 1,
                    Gender     = xingbie
                };
                entity.User.Add(user);
                user.UserExtend        = new UserExtend();
                user.UserExtend.Banned = 0;
                userSMS.State          = 1;

                user.UserExtend.ExperienceLevel = 1;
                ExperienceLevel experienceLevel = entity.ExperienceLevel.Where(o => o.ExperienceLevelValue == user.UserExtend.ExperienceLevel).FirstOrDefault();
                user.UserExtend.ExperienceValue = experienceLevel.ExperienceValueMin;
                if (user.Gender == "男")
                {
                    user.UserExtend.ExperienceName = experienceLevel.NameMan;
                }
                else
                {
                    user.UserExtend.ExperienceName = experienceLevel.NameWoman;
                }
                user.InitBeforeSave();
                entity.SaveChanges();
                Authentication authentication = new Authentication(user.Tel, password);
                if (!string.IsNullOrEmpty(authentication.state))
                {
                    return(authentication.state);
                }
                return(authentication.tokenUserTime());
            }
        }