生成随机码

public static string GetCustomerEmailVerificationCode(int customerid)
        {
            string key="";

            key = Md5Str(string.Format("{0}{1}", System.Guid.NewGuid().ToString(), customerid));

            return key;

        }
        
        private static string Md5Str(string str)
        {
            string cl = str;
            string pwd = "";
            string temp = "";

            System.Security.Cryptography.MD5CryptoServiceProvider md5 = new System.Security.Cryptography.MD5CryptoServiceProvider();
           
            byte[] s = md5.ComputeHash(Encoding.UTF8.GetBytes(cl));
           
            for (int i = 0; i < s.Length; i++)
            {               
                temp = s[i].ToString("X");
                if (temp.Length < 2)
                    temp = "0" + temp;
                pwd = pwd + temp;
            }
            return pwd;
        }

posted on 2013-08-19 11:18  西湖浪子  阅读(121)  评论(0)    收藏  举报