示例#1
0
        public static string CreateVerifyCode(int length)
        {
            string text   = string.Empty;
            Random random = new Random();

            while (text.Length < length)
            {
                int  num = random.Next();
                char c;
                if (num % 3 == 0)
                {
                    c = (char)(97 + (ushort)(num % 26));
                }
                else if (num % 4 == 0)
                {
                    c = (char)(65 + (ushort)(num % 26));
                }
                else
                {
                    c = (char)(48 + (ushort)(num % 10));
                }
                if (c != '0' && c != 'o' && c != '1' && c != '7' && c != 'l' && c != '9' && c != 'g' && c != 'I')
                {
                    text += c.ToString();
                }
            }
            Globals.RemoveVerifyCookie();
            HttpCookie httpCookie = new HttpCookie("VerifyCode");

            httpCookie.Value = HiCryptographer.Encrypt(text);
            HttpContext.Current.Response.Cookies.Add(httpCookie);
            return(text);
        }
示例#2
0
        public static bool CheckVerifyCode(string verifyCode)
        {
            bool result;

            if (HttpContext.Current.Request.Cookies["VerifyCode"] == null)
            {
                Globals.RemoveVerifyCookie();
                result = false;
            }
            else
            {
                bool flag = string.Compare(HiCryptographer.Decrypt(HttpContext.Current.Request.Cookies["VerifyCode"].Value), verifyCode, true, CultureInfo.InvariantCulture) == 0;
                Globals.RemoveVerifyCookie();
                result = flag;
            }
            return(result);
        }