Пример #1
0
        /// <summary>
        ///     验证账号密码
        /// </summary>
        /// <param name="username">用户名</param>
        /// <param name="password">密码</param>
        /// <returns>是否验证通过</returns>
        public static bool VerifyPassword(string username, string password)
        {
            var account = GetAccount(username);

            if (account == null)
            {
                return(false);
            }
            return(account.PasswordMd5 == Md5Password.MD5Create(password));
        }
Пример #2
0
        /// <summary>
        ///     创建账号
        /// </summary>
        /// <param name="userName">用户名</param>
        /// <param name="password">密码</param>
        /// <returns>影响行数 </returns>
        public static int CreatAccout(string userName, string password)
        {
            //检查用户名是否已经存在
            if (GetAccount(userName) != null)
            {
                return(0);
            }
            var account = new Account
            {
                UserName    = userName,
                PasswordMd5 = Md5Password.MD5Create(password),
                LastLoginin = DateTime.Now,
                Enable      = true
            };

            using (var context = new EntityContext())
            {
                context.Accounts.Add(account);
                return(context.SaveChanges());
            }
        }