コード例 #1
0
        public async Task <Tuple <bool, string> > GetLoginResponse(string email, string password)
        {
            Tuple <bool, string> res = null;

            LoginUser u = new LoginUser(email, password);

            if (u.IsValid())
            {
                bool bSuccess = await loginServices.LoginAsync(u.Email, u.Password);

                if (bSuccess)
                {
                    res = new Tuple <bool, string>(true, "Login has been successful.");
                }
                else
                {
                    res = new Tuple <bool, string>(false, "Login failed. Incorrect email and/or password.");
                }
            }
            else
            {
                if (u.HasBlanks())
                {
                    res = new Tuple <bool, string>(false, "Login failed. Login information incomplete.");
                }
                else if (u.InValidEmail())
                {
                    res = new Tuple <bool, string>(false, "Login failed. Please enter a valid email address.");
                }
            }

            return(res);
        }
コード例 #2
0
        public void Login()
        {
            LoginUser user = new LoginUser();

            user.IsValid("*****@*****.**", "123456");

            Assert.IsTrue(false);
        }
コード例 #3
0
 public ActionResult Login(LoginUser user)
 {
     if (ModelState.IsValid)
     {
         if (user.IsValid(user.UserName, user.Password))
         {
             var bID = user.getBusinessId(user.UserName);
             System.Web.HttpContext.Current.Session["id"] = bID;
             FormsAuthentication.SetAuthCookie(user.UserName, user.RememberMe);
             return RedirectToAction("Dashboard_v1", "Dashboard");
         }
         else
         {
             ModelState.AddModelError("", "Login data is incorrect!");
         }
     }
     return View(user);
 }
コード例 #4
0
        private void btnLogin_Click(object sender, EventArgs e)
        {
            string username = txtUserName.Text.Trim();
            string password = CommonHelper.GetMD5(txtPassword.Text.Trim());

            LoginUser lu = new LoginUser(username, password);

            LoginUser.LoginResult lr = lu.IsValid();

            if (lr == LoginUser.LoginResult.UserNameError)
            {
                CommonHelper.FailedReply("用户名错误!");
                this.DialogResult = DialogResult.Cancel;
            }
            else if (lr == LoginUser.LoginResult.PasswordError)
            {
                CommonHelper.FailedReply("密码错误!");
                this.DialogResult = DialogResult.Cancel;
            }
            else if (lr == LoginUser.LoginResult.LockedError)
            {
                CommonHelper.FailedReply("用户锁定!");
                this.DialogResult = DialogResult.Cancel;
            }
            else if (lr == LoginUser.LoginResult.DeletedError)
            {
                CommonHelper.FailedReply("用户不存在!");
                this.DialogResult = DialogResult.Cancel;
            }
            else
            {
                CommonHelper.SuccessReply("登陆成功!");
                this.DialogResult = DialogResult.OK;
            }

            //while (sdr.Read())
            //{
            //    //判断是否被删除
            //    if (Convert.ToBoolean(sdr["IsDeleted"]) == true)
            //    {
            //        CommonHelper.SuccessReply("此用户已被删除!");
            //        this.DialogResult = DialogResult.Cancel;
            //    }
            //    //判断是否被锁定
            //    else if (Convert.ToBoolean(sdr["IsLocked"]) == true)
            //    {
            //        CommonHelper.SuccessReply("此用户已被锁定!");
            //        this.DialogResult = DialogResult.Cancel;
            //    }
            //    //判断用户名或密码错误
            //    else if (sdr["UserName"].ToString() != user && sdr["Password"].ToString() == password)
            //    {
            //        CommonHelper.SuccessReply("用户名错误!");
            //        this.DialogResult = DialogResult.Cancel;
            //    }
            //    else if (sdr["Password"].ToString() != password && sdr["UserName"].ToString() == user)
            //    {
            //        CommonHelper.SuccessReply("密码错误!");
            //        this.DialogResult = DialogResult.Cancel;
            //    }
            //    else if (sdr["Password"].ToString() != password && sdr["UserName"].ToString() != user)
            //    {
            //        CommonHelper.SuccessReply("用户名或密码错误!");
            //        this.DialogResult = DialogResult.Cancel;
            //    }
            //    //正常登录
            //    else
            //    {
            //        userid = user;
            //        CommonHelper.SuccessReply("欢迎使用本系统!");
            //        this.DialogResult = DialogResult.OK;
            //    }
            //}
            //sdr.Close();
            //conn.Close();
        }