Exemple #1
0
    public static string UpdatePassword(string oldpwd, string newpwd, int userid)
    {
        SHA256CryptoServiceProvider sha256crypto = new SHA256CryptoServiceProvider();

        oldpwd = CommonMethods.Decrypt(oldpwd);
        byte[] b = sha256crypto.ComputeHash(Encoding.UTF8.GetBytes(oldpwd));
        oldpwd = CommonMethods.BytesToHexString(b);
        SqlQueryCondition sqlcondition1 = new SqlQueryCondition(UserField.Id, SqlQueryConditionOperator.Equal, userid);
        SqlQueryCondition sqlcondition2 = new SqlQueryCondition(UserField.Password, SqlQueryConditionOperator.Equal, oldpwd);

        if (UserDAO.Select(new UserField[] { UserField.Id },
                           new SqlQueryCondition(new SqlQueryCondition[] { sqlcondition1, sqlcondition2 }, SqlQueryLogicalOperator.And)).Length == 0) //学号不存在或者状态码或密码不正确
        {
            return("原密码不正确!");
        }
        else
        {
            newpwd = CommonMethods.Decrypt(newpwd);
            if (newpwd.Length < 8 || newpwd.Length > 16)
            {
                return("新密码长度不符合要求!");
            }
            b      = sha256crypto.ComputeHash(Encoding.UTF8.GetBytes(newpwd));
            newpwd = CommonMethods.BytesToHexString(b);
            UserDAO.Update(new UserField[] { UserField.Password }, new object[] { newpwd }, sqlcondition1);
            UserLogDAO.Insert(userid, "updpwd{}");
            return("true");
        }
    }
Exemple #2
0
        /// <summary>
        /// ¼ÓÃÜ×Ö·û´®
        /// </summary>
        /// <param name="content"></param>
        /// <returns></returns>
        private string EncryString(string content)
        {
            ConfigSave config = Program.MainForm.Config;

            byte[] arrStr = DefaultEncode.GetBytes(content);
            byte[] pwd    = config.EncryPassword;
            byte[] enStr  = PasswordHash.AESEncrypt(arrStr, pwd);
            return(CommonMethods.BytesToHexString(enStr, false));
        }
Exemple #3
0
        /// <summary>
        /// 创建新的密钥
        /// </summary>
        /// <returns></returns>
        public static string CreateSecret()
        {
            StringBuilder sb = new StringBuilder();

            for (int i = 0; i < 3; i++)
            {
                Guid   id  = Guid.NewGuid();
                byte[] arr = id.ToByteArray();
                sb.Append(CommonMethods.BytesToHexString(arr, false));
                sb.Append("-");
            }
            sb.Remove(sb.Length - 1, 1);
            return(sb.ToString());
        }
Exemple #4
0
        /// <summary>
        /// ¼ÓÃÜ×Ö·û´®
        /// </summary>
        /// <param name="content"></param>
        /// <returns></returns>
        private string EncryString(string content)
        {
            byte[] arrStr = DefaultEncode.GetBytes(content);
            byte   tmp    = 0;

            for (int i = 0; i < arrStr.Length; i++)
            {
                tmp       = (byte)(arrStr[i] ^ 256);
                tmp       = (byte)((tmp + 128) % 256);
                arrStr[i] = tmp;
            }
            //return Convert.ToBase64String(arrStr);
            return(CommonMethods.BytesToHexString(arrStr));
        }
Exemple #5
0
 /// <summary>
 /// 把值转成字符串
 /// </summary>
 /// <param name="value"></param>
 /// <returns></returns>
 private static string ValueToString(object value)
 {
     if (value == null)
     {
         return("");
     }
     if (value is Enum)
     {
         return(((int)value).ToString());
     }
     if (value is byte[])
     {
         return(CommonMethods.BytesToHexString((byte[])value));
     }
     if (value is bool)
     {
         return(((bool)value)?"1":"0");
     }
     return(value.ToString());
 }
 /// <summary>
 /// 把值转成字符串
 /// </summary>
 /// <param name="value"></param>
 /// <returns></returns>
 private static object ToJsonValue(object value)
 {
     if (value == null)
     {
         return(null);
     }
     if (value is Enum)
     {
         return((int)value);
     }
     if (value is byte[])
     {
         return(CommonMethods.BytesToHexString((byte[])value));
     }
     if (value is bool)
     {
         return(((bool)value) ? 1 :0);
     }
     return(value);
 }
        /// <summary>
        /// 把查询条件加到条件的字符串里
        /// </summary>
        /// <param name="value">值</param>
        /// <param name="type">数据库里边的类型</param>
        /// <returns></returns>
        public static string FormatValue(object value, DbType type, DBInfo db)
        {
            if (value == null)
            {
                return(null);
            }

            switch (type)
            {
            case DbType.AnsiString:
            case DbType.AnsiStringFixedLength:
            case DbType.String:
            case DbType.StringFixedLength:
                return("'" + value.ToString().Replace("'", "''") + "'");

            case DbType.Guid:
                if (value is Guid)
                {
                    return(Buffalo.Kernel.CommonMethods.GuidToString((Guid)value));
                }
                return(value.ToString());

            case DbType.DateTime:
            case DbType.Time:
            case DbType.Date:
            case DbType.DateTime2:
            case DbType.DateTimeOffset:
                return(db.CurrentDbAdapter.GetDateTimeString(value));

            case DbType.Decimal:
            case DbType.Double:
            case DbType.Int32:
            case DbType.Int16:
            case DbType.Int64:
            case DbType.SByte:
            case DbType.Byte:
            case DbType.Currency:
            case DbType.UInt16:
            case DbType.UInt32:
            case DbType.UInt64:
            case DbType.VarNumeric:
            case DbType.Single:
                return(value.ToString().Replace(" ", ""));

            case DbType.Binary:
                byte[] binaryValue = value as byte[];
                if (binaryValue != null)
                {
                    string hexVal = CommonMethods.BytesToHexString(binaryValue);
                    return("0x" + hexVal);
                }
                return("");

            case DbType.Boolean:
                bool valBool = Convert.ToBoolean(value);
                if (valBool == true)
                {
                    return("1");
                }
                else
                {
                    return("0");
                }

            default:
                return(null);
            }
        }