Example #1
0
    public bool Login(string username, string password, string captcha)
    {
        if (username.Trim() == string.Empty)
        {
            throw new Exception("用户名不能为空!");
        }
        if (password.Trim() == string.Empty)
        {
            throw new Exception("密码不能为空!");
        }
        if (captcha.Trim() == string.Empty)
        {
            throw new Exception("验证码不能为空!");
        }
        if (!VerCode.CheckCode("log", captcha))
        {
            throw new Exception("验证码验证错误!");
        }
        var su = SystemUser.Login(username, password);

        if (su != null)
        {
            HttpCookie cookie = new HttpCookie("login_Username", username)
            {
                Expires = DateTime.Now.AddYears(1)
            };
            HttpContext.Current.Response.Cookies.Add(cookie);
            return(true);
        }
        else
        {
            return(false);
        }
    }
Example #2
0
    public string Login(string username, string password)
    {
        if (username.Trim() == string.Empty)
        {
            throw new Exception("用户名不能为空!");
        }
        if (password.Trim() == string.Empty)
        {
            throw new Exception("密码不能为空!");
        }
        var su = SystemUser.Login(username, password);

        if (su != null)
        {
            HttpCookie cookie = new HttpCookie("login_Username", username)
            {
                Expires = DateTime.Now.AddYears(1)
            };
            HttpContext.Current.Response.Cookies.Add(cookie);
            return(su.UserID.ToString());
        }
        else
        {
            return(null);
        }
    }