Esempio n. 1
0
        public static bool UpdatePsw(string userId, string psw, string newPsw, string confirmNewPsw)
        {
            bool flag = string.IsNullOrEmpty(userId);

            if (flag)
            {
                throw new Exception("用户名或密码错误!");
            }
            bool flag2 = newPsw != confirmNewPsw;

            if (flag2)
            {
                throw new Exception("两次输入的密码不匹配!");
            }
            User user  = UserUtils.GetUser(userId);
            bool flag3 = user == null;

            if (flag3)
            {
                throw new Exception("用户名或密码错误!");
            }
            bool disabled = user.Disabled;

            if (disabled)
            {
                throw new Exception("当前用户名已被停用!");
            }
            SystemInfo systemInfo = SystemInfoUtils.GetSystemInfo();
            bool       flag4      = systemInfo != null && systemInfo.PswLength > 0 && systemInfo.PswLength > newPsw.Length;

            if (flag4)
            {
                throw new Exception(string.Format("密码长度小于系统指定最短长度({0})!", systemInfo.PswLength));
            }
            bool flag5 = user.Password != PasswordSec.Encode(userId, psw);

            if (flag5)
            {
                throw new Exception("用户名或密码错误!");
            }
            Database database = LogicContext.GetDatabase();
            HSQL     sql      = new HSQL(database);

            sql.Clear();
            sql.Add("UPDATE USERS SET");
            sql.Add("USERS_PASSWORD = :USERS_PASSWORD");
            sql.Add("WHERE USERS_USERID = :USERS_USERID");
            sql.ParamByName("USERS_PASSWORD").Value = PasswordSec.Encode(userId, newPsw);
            sql.ParamByName("USERS_USERID").Value   = userId;
            bool flag6 = database.ExecSQL(sql) != 1;

            if (flag6)
            {
                throw new Exception(string.Format("用户({0})密码修改失败!", userId));
            }
            CacheEvent.TableIsUpdated("USERS");
            return(true);
        }
Esempio n. 2
0
        public static bool Login(string userId, string password, string clientIp)
        {
            bool flag = string.IsNullOrEmpty(userId);
            bool result;

            if (flag)
            {
                result = false;
            }
            else
            {
                userId = userId.ToUpper();
                User user  = UserUtils.GetUser(userId);
                bool flag2 = user == null;
                if (flag2)
                {
                    throw new Exception("用户名或密码错误!");
                }
                bool disabled = user.Disabled;
                if (disabled)
                {
                    throw new Exception("当前用户名已被停用!");
                }
                bool flag3 = user.Password != PasswordSec.Encode(userId, password);
                if (flag3)
                {
                    throw new Exception("用户名或密码错误!");
                }
                LogicSession logicSession = AuthUtils.SignIn(userId, clientIp);
                bool         flag4        = logicSession != null;
                if (flag4)
                {
                    logicSession.UserName = user.UserName;
                    LogicContext current = LogicContext.Current;
                    bool         flag5   = current != null;
                    if (flag5)
                    {
                        current.SetLogicSession(logicSession);
                    }
                }
                result = true;
            }
            return(result);
        }
Esempio n. 3
0
        public static bool ResetPsw(string userId, string resetPsw)
        {
            Database database = LogicContext.GetDatabase();
            HSQL     sql      = new HSQL(database);

            sql.Clear();
            sql.Add("UPDATE USERS SET");
            sql.Add("USERS_PASSWORD = :USERS_PASSWORD");
            sql.Add("WHERE USERS_USERID = :USERS_USERID");
            sql.ParamByName("USERS_PASSWORD").Value = PasswordSec.Encode(userId, resetPsw);
            sql.ParamByName("USERS_USERID").Value   = userId;
            bool flag = database.ExecSQL(sql) != 1;

            if (flag)
            {
                throw new Exception(string.Format("用户({0})密码修改失败!", userId));
            }
            CacheEvent.TableIsUpdated("USERS");
            return(true);
        }