コード例 #1
0
        /// <summary>
        /// 更新密码
        /// </summary>
        /// <param name="db"></param>
        /// <param name="id"></param>
        /// <param name="password"></param>
        /// <returns></returns>
        public static async Task <bool> UpdatePassword(DBHelper db, int id, string password)
        {
            string salt = MakeCommon.MakeSalt(id.ToString());
            string p    = MakeCommon.MakeMD5(salt + id + password + id + salt);
            string pwd  = ConcealCommon.EncryptDES(salt + p + salt);

            string sql = @"UPDATE t_user set `password`=@password, `salt`=@salt WHERE `id`=@id";

            return(await db.ExecAsync(sql, new { password = pwd, salt = salt, id = id }) > 0);
        }
コード例 #2
0
        public async Task <Result> Login(In <LoginIn> inData)
        {
            Result result = await VerifyLogin(inData.data);

            if (!result.result)
            {
                return(result);
            }
            DBHelper db   = new DBHelper();
            t_user   user = await UserDao.GetUser(db, inData.data.user_name);

            bool password_flag = VerifyCommon.VerifyPassword(user.id, user.salt, user.password, inData.data.password);

            if (!password_flag)
            {
                db.Close();
                result.msg = "用户名或密码错误";
                return(result);
            }

            LoginResult loginResult = new LoginResult
            {
                user_id         = user.id,
                department_name = await DepartmentDao.GetDepartmentName(db, user.department_id),
                position_name   = await PositionDao.GetPositionName(db, user.position_id),
                department_id   = user.department_id,
                position_id     = user.position_id,
                name            = user.real_name,
                token           = ConcealCommon.EncryptDES(user.id + DateTime.Now.ToString("yyy-MM-dd HH:mm:ss:ms")),
                user_name       = user.user_name,
            };

            db.Close();

            await RedisHelper.Instance.SetStringKeyAsync($"user-multi-token:{loginResult.token}", loginResult, TimeSpan.FromHours(4));

            Result <LoginResult> result1 = new Result <LoginResult>
            {
                data   = loginResult,
                result = true,
                msg    = "登录成功"
            };

            return(result1);
        }