Beispiel #1
0
        /// <summary>
        /// 登录
        /// </summary>
        /// <param name="account">用户名</param>
        /// <param name="password">密码</param>
        /// <returns>登录状态</returns>
        //public static SignInStatus PasswordSignIn(string account, string password)
        //{
        //    using (MR_DataClassesDataContext _db = new MR_DataClassesDataContext())
        //    {
        //        var truePassword = _db.tbl_UserAccount.Where(p => p.user_Account == account).ToList();

        //        if (truePassword.Count() == 0)
        //        {
        //            return SignInStatus.UndefinedAccount;
        //        }
        //        else if (truePassword[0].user_Password == DESEncryption.DesEncrypt(password))
        //        {
        //            FormsAuthentication.SetAuthCookie(account, true, FormsAuthentication.FormsCookiePath);
        //            return SignInStatus.Success;
        //        }
        //        else
        //        {
        //            return SignInStatus.Failure;
        //        }
        //    }
        //}
        public static SignInStatus SignInWithPassword(string account, string password)
        {
            var validate = SqlHepler.ExecuteSqlQuery("Select * From tbl_UserAccount Where user_Account=@name", new SqlParameter("@name", account));

            if (validate.Count == 0)
            {
                return(SignInStatus.UndefinedAccount);
            }
            else if (validate[0].user_Password == DESEncryption.DesEncrypt(password))
            {
                CookieHepler.SetCookie("user", account);
                CookieHepler.SetCookie("userid", validate[0].user_Id.ToString());
                CookieHepler.SetCookie("usertype", validate[0].user_IsAdmin.ToString());
                //HttpCookie cookie = new HttpCookie("user", account);
                //cookie.Expires = DateTime.Now.AddHours(12);
                //HttpContext.Current.Response.Cookies.Add(cookie);
                //cookie = new HttpCookie("userid", validate[0].user_Id.ToString());
                //cookie.Expires = DateTime.Now.AddHours(12);
                //HttpContext.Current.Response.Cookies.Add(cookie);
                //cookie = new HttpCookie("usertype", validate[0].user_IsAdmin.ToString());
                //cookie.Expires = DateTime.Now.AddHours(12);
                //HttpContext.Current.Response.Cookies.Add(cookie);
                return(SignInStatus.Success);
            }
            else
            {
                return(SignInStatus.Failure);
            }
        }
        /// <summary>
        /// 修改密码
        /// </summary>
        /// <param name="account">账号</param>
        /// <param name="oldpassword">原密码</param>
        /// <param name="newpassword">新密码</param>
        /// <returns>成功 or 失败,错误信息</returns>
        public static RequestResult ChangePassword(string account, string oldpassword, string newpassword)
        {
            if (oldpassword == newpassword)
            {
                return(new RequestResult()
                {
                    Succeeded = false, Error = "新密码不能与原密码相同"
                });
            }
            using (MR_DataClassesDataContext _db = new MR_DataClassesDataContext())
            {
                oldpassword = DESEncryption.DesEncrypt(oldpassword);
                var rightPassword = _db.tbl_UserAccount.Where(p => p.user_Account == account && p.user_Password == oldpassword).ToList();

                if (rightPassword.Count() == 0)
                {
                    return(new RequestResult()
                    {
                        Succeeded = false, Error = "原密码输入错误"
                    });
                }
                else
                {
                    newpassword = DESEncryption.DesEncrypt(newpassword);
                    var newAccount = _db.tbl_UserAccount.SingleOrDefault(p => p.user_Account == account);
                    newAccount.user_Password = newpassword;
                    _db.SubmitChanges();
                    _db.AlterUserAlterTime(newAccount.user_Id);
                    return(new RequestResult()
                    {
                        Succeeded = true, Error = "密码 更改成功"
                    });
                }
            }
        }
 /// <summary>
 /// 重置密码
 /// </summary>
 /// <param name="account">账号</param>
 /// <param name="password">密码</param>
 /// <returns>成功 or 失败,错误信息</returns>
 public static RequestResult ResetPassword(string account, string password)
 {
     using (MR_DataClassesDataContext _db = new MR_DataClassesDataContext())
     {
         password = DESEncryption.DesEncrypt(password);
         var newAccount = _db.tbl_UserAccount.SingleOrDefault(p => p.user_Account == account);
         newAccount.user_Password = password;
         _db.SubmitChanges();
         return(new RequestResult()
         {
             Succeeded = true
         });
     }
 }
Beispiel #4
0
 /// <summary>
 /// 创建账户
 /// </summary>
 /// <param name="account">用户名</param>
 /// <param name="password">密码</param>
 /// <returns>成功 or 失败,错误信息</returns>
 public static RequestResult Create(string account, string password)
 {
     using (MRDataEntities _db = new MRDataEntities())
     //using (MR_DataClassesDataContext _db = new MR_DataClassesDataContext())
     {
         var hasAccount = _db.tbl_UserAccount.Where(p => p.user_Account == account);
         if (hasAccount.Count() > 0)
         {
             return(new RequestResult()
             {
                 Succeeded = false, Error = "用户名已存在"
             });
         }
         else
         {
             password = DESEncryption.DesEncrypt(password);
             //string guid;
             //do
             //{
             //    guid = Guid.NewGuid().ToString("N").ToUpper();
             //} while (_db.tbl_UserAccount.Where(p => p.user_Id == guid).Count() != 0);
             var addAccount = new tbl_UserAccount()
             {
                 //user_Id = guid,
                 user_Id         = Guid.NewGuid().ToString("N").ToUpper(),
                 user_Account    = account,
                 user_Password   = password,
                 user_IsAdmin    = false,
                 user_CreateTime = DateTime.Now
             };
             addAccount.user_Avatar = "User_1.jpg";
             addAccount.user_Cover  = "Cover_1.jpg";
             _db.tbl_UserAccount.Add(addAccount);
             _db.SaveChanges();
             //_db.tbl_UserAccount.InsertOnSubmit(addAccount);
             //_db.SubmitChanges();
             //_db.SetUserTime(guid);
             return(new RequestResult()
             {
                 Succeeded = true
             });
         }
     }
 }
        /// <summary>
        /// 登录
        /// </summary>
        /// <param name="account">用户名</param>
        /// <param name="password">密码</param>
        /// <returns>登录状态</returns>
        public static SignInStatus PasswordSignIn(string account, string password)
        {
            using (MR_DataClassesDataContext _db = new MR_DataClassesDataContext())
            {
                var truePassword = _db.tbl_UserAccount.Where(p => p.user_Account == account).ToList();

                if (truePassword.Count() == 0)
                {
                    return(SignInStatus.UndefinedAccount);
                }
                else if (truePassword[0].user_Password == DESEncryption.DesEncrypt(password))
                {
                    FormsAuthentication.SetAuthCookie(account, true, FormsAuthentication.FormsCookiePath);
                    return(SignInStatus.Success);
                }
                else
                {
                    return(SignInStatus.Failure);
                }
            }
        }