Пример #1
0
        /// <summary>
        /// 登录
        /// </summary>
        /// <param name="userName">用户名</param>
        /// <param name="password">密码</param>
        /// <param name="userInfo">用户信息</param>
        /// <param name="menus">用户可访问菜单</param>
        /// <param name="errorMessage">错误信息</param>
        /// <returns></returns>
        public bool Login(string userName, string password, out Entity userInfo, out Dictionary <int, BF_MENU.Entity> menus, out string errorMessage)
        {
            userInfo     = null;
            menus        = new Dictionary <int, BF_MENU.Entity>();
            errorMessage = string.Empty;
            DataRow dr = GetRow("NAME=?", userName);

            if (dr == null)
            {
                errorMessage = "账号不存在";
                return(false);
            }
            Entity entity = ToEntity <Entity>(dr);

            if (entity.IS_LOCKED == 1)
            {
                errorMessage = "账号已经被锁定";
                return(false);
            }
            if (entity.IS_ENABLE != 1)
            {
                errorMessage = "账号已经停用";
                return(false);
            }

            //加密
            string psd1 = BMD5.Encrypt(password, userName);
            //解密再加密
            string psd2 = BMD5.Encrypt(DeCodePassword(password), userName);

            if (entity.PASSWORD != psd1 && entity.PASSWORD != psd2)
            {
                int failCount = entity.LOGIN_FAIL_COUNT + 1;
                errorMessage = "密码错误,还有" + (BF_SYS_CONFIG.MaxLoginFailCount - failCount) + "次机会";
                SetLoginFailCount(userName, failCount);
                return(false);
            }

            //记录登录情况
            Dictionary <string, object> dic = new Dictionary <string, object>();

            dic.Add("LOGIN_FAIL_COUNT", 0);
            dic.Add("LOGIN_COUNT", entity.LOGIN_COUNT + 1);
            dic.Add("LAST_LOGIN_TIME", DateTime.Now);

            int i = Update(dic, "NAME=?", userName);

            if (i < 1)
            {
                errorMessage = "出现了未知错误";
                return(false);
            }
            //用户信息
            userInfo          = entity;
            userInfo.PASSWORD = "******";
            //可访问菜单
            menus = BF_ROLE.Instance.GetMenusByRoles(entity.ROLE_IDS);

            return(true);
        }
Пример #2
0
        /// <summary>
        /// 重置密码
        /// </summary>
        /// <param name="id">用户ID</param>
        /// <returns></returns>
        public int ResetPassword(int id)
        {
            Entity entity = GetEntityByKey <Entity>(id);

            if (entity == null)
            {
                return(0);
            }
            string psd = BMD5.Encrypt(BF_SYS_CONFIG.DefaultPassword, entity.NAME);
            Dictionary <string, object> dic = new Dictionary <string, object>();

            dic.Add("PASSWORD", psd);
            dic.Add("UPDATE_TIME", DateTime.Now);
            dic.Add("UPDATE_UID", SystemSession.UserID);

            return(UpdateByKey(dic, id));
        }
Пример #3
0
        /// <summary>
        /// 修改密码
        /// </summary>
        /// <param name="oldPassword">原密码</param>
        /// <param name="newPassword">新密码</param>
        /// <param name="errorMessage">错误信息</param>
        /// <returns></returns>
        public bool ChangePassword(string oldPassword, string newPassword, out string errorMessage)
        {
            errorMessage = string.Empty;
            if (string.IsNullOrWhiteSpace(oldPassword))
            {
                errorMessage = "原密码不可为空";
                return(false);
            }
            if (string.IsNullOrWhiteSpace(newPassword))
            {
                errorMessage = "新密码不可为空";
                return(false);
            }
            if (SystemSession.UserID < 1)
            {
                errorMessage = "未登录";
                return(false);
            }
            Entity entity = GetEntityByKey <Entity>(SystemSession.UserID);

            if (entity == null)
            {
                errorMessage = "未知用户";
                return(false);
            }

            string oldpsd = BMD5.Encrypt(oldPassword, entity.NAME);

            if (oldpsd != entity.PASSWORD)
            {
                errorMessage = "原密码不正确";
                return(false);
            }
            string newpsd = BMD5.Encrypt(newPassword, entity.NAME);
            Dictionary <string, object> dic = new Dictionary <string, object>();

            dic.Add("PASSWORD", newpsd);
            dic.Add("UPDATE_TIME", DateTime.Now);
            dic.Add("UPDATE_UID", SystemSession.UserID);

            return(UpdateByKey(dic, entity.ID) > 0);
        }
Пример #4
0
 /// <summary>
 /// 获取账号的默认密码
 /// </summary>
 /// <param name="username"></param>
 /// <returns></returns>
 private string GetDefaultPassword(string username)
 {
     return(BMD5.Encrypt(BF_SYS_CONFIG.DefaultPassword, username));
 }