예제 #1
0
        public bool IsUserOrNot(string userId, string strPwd, out string strErrorMessage)
        {
            strErrorMessage = "";
            string    sql           = "SELECT ID,Name,Passwd,RegDate FROM Users WHERE ID='" + userId + "'  AND Valid = '1'";
            DataTable dataTableUser = m_SqlHelper.ExecuteDataTable(sql);

            if (dataTableUser.Rows.Count == 0)
            {
                strErrorMessage = "用户不存在!";
                return(false);
            }
            else
            {
                string encryptPasswordBase64 = HisEncryption.EncodeString(dataTableUser.Rows[0]["RegDate"].ToString(), HisEncryption.PasswordLength, strPwd);
                if (encryptPasswordBase64 == dataTableUser.Rows[0]["Passwd"].ToString())
                {
                    UserName = dataTableUser.Rows[0]["Name"].ToString();
                    return(true);
                }
                else
                {
                    strErrorMessage = "密码错误!";
                    return(false);
                }
            }
        }
예제 #2
0
        /// <summary>
        /// 加密字符串sql用,形式为Char(xx)+Char(xx)...
        /// </summary>
        /// <param name="buffer">密钥</param>
        /// <param name="len">长度=8</param>
        /// <param name="key">传入的明码密码</param>
        /// <returns></returns>
        public static string EncodeStringSql(string buffer, int len, string key)
        {
            if (buffer == null)
            {
                throw new ArgumentNullException("buffer", "传入密钥为空");
            }
            if (string.IsNullOrEmpty(key))
            {
                key = string.Empty;
            }

            char[] pbuffer = new char[1024];
            char[] pkey    = new char[80];
            string s       = "";

            char[] ckey;

            HisEncryption encryption = new HisEncryption();

            buffer.ToCharArray().CopyTo(pbuffer, 0);
            key.ToCharArray().CopyTo(pkey, 0);
            encryption.Secret(pbuffer, len, pkey);
            ckey = encryption.EncryptPassword.ToCharArray();
            s    = "char(" + Convert.ToByte(ckey[0]).ToString() + ")";
            for (int i = 1; i < len; i++)
            {
                s = s + "+char(" + Convert.ToByte(ckey[i]).ToString() + ")";
            }
            s = s + "+char(0)";
            return(s);
        }
예제 #3
0
 private static byte[] CharArray2ByteArray(int len, HisEncryption encryption)
 {
     byte[] ret = new byte[len];
     for (int i = 0; i < len; i++)
     {
         ret[i] = Convert.ToByte(encryption.pass[i]);
     }
     return(ret);
 }
예제 #4
0
        /// <summary>
        /// 加密串
        /// </summary>
        /// <param name="buffer">密钥</param>
        /// <param name="len">长度=8</param>
        /// <param name="key">传入的明码密码</param>
        /// <returns>返回字符数组</returns>
        public static byte[] EncodeString2ByteArray(string buffer, int len, string key)
        {
            if (buffer == null)
            {
                throw new ArgumentNullException("buffer", "传入密钥为空");
            }
            if (string.IsNullOrEmpty(key))
            {
                key = string.Empty;
            }

            char[] pbuffer = new char[1024];
            char[] pkey    = new char[80];

            HisEncryption encryption = new HisEncryption();

            buffer.ToCharArray().CopyTo(pbuffer, 0);
            key.ToCharArray().CopyTo(pkey, 0);
            encryption.Secret(pbuffer, len, pkey);

            return(CharArray2ByteArray(len, encryption));
        }