コード例 #1
0
        private void UserControl_Loaded(object sender, RoutedEventArgs e)
        {
            ValidCode validCode = new ValidCode(5, ValidCode.CodeType.Alphas);

            m_iValidCode.Source = BitmapFrame.Create(validCode.CreateCheckCodeImage());
            m_sValidCode        = validCode.CheckCode;
        }
コード例 #2
0
        private void m_iValidCode_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            ValidCode validCode = new ValidCode(5, ValidCode.CodeType.Alphas);

            m_iValidCode.Source = BitmapFrame.Create(validCode.CreateCheckCodeImage());
            m_sValidCode        = validCode.CheckCode;
        }
コード例 #3
0
        public async Task <IHttpActionResult> PutValidCode(int id, ValidCode validCode)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != validCode.Id)
            {
                return(BadRequest());
            }

            db.Entry(validCode).State = EntityState.Modified;

            try
            {
                await db.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!ValidCodeExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
コード例 #4
0
        public ActionResult Code()
        {
            ValidCode validCode = new ValidCode();
            string    code      = validCode.CreateVerifyCode();

            TempData["ValidCode"] = code;
            return(File(validCode.CodeImageGetBuffer(code), "image/jpeg"));
        }
コード例 #5
0
        public async Task <IHttpActionResult> GetAddressModels(int id)
        {
            ValidCode validCode = await db.ValidCodes.FindAsync(id);

            if (validCode == null)
            {
                return(NotFound());
            }

            return(Ok(validCode));
        }
コード例 #6
0
        public MainLoginVM()
        {
            validCode = new ValidCode(4, ValidCode.CodeType.Characters);

            ValidCodeImg = BitmapFrame.Create(validCode.CreateCheckCodeImage());

            LoginUcView = Visibility.Visible;
            RegUcView   = Visibility.Collapsed;
            ResetUcView = Visibility.Collapsed;
            ErrIsShow   = Visibility.Collapsed;

            CheckRememberUser();
        }
コード例 #7
0
        /// <summary>
        /// 发送验证邮箱的请求
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void m_btnSendEmail_Click(object sender, RoutedEventArgs e)
        {
            if (m_tbValidCode.Text.ToLower().Equals(""))
            {
                m_tbHelp.Text = "未填写验证码";
                return;
            }
            else if (!m_tbValidCode.Text.ToLower().Equals(m_sValidCode.ToLower()))
            {
                m_tbHelp.Text = "验证码不正确";
                ValidCode validCode = new ValidCode(5, ValidCode.CodeType.Alphas);
                m_iValidCode.Source = BitmapFrame.Create(validCode.CreateCheckCodeImage());
                m_sValidCode        = validCode.CheckCode;
                return;
            }
            if (m_tbEmail.Text.Length > 32)
            {
                m_tbHelp.Text = "邮箱过长";
                return;
            }
            Regex r = new Regex("^\\s*([A-Za-z0-9_-]+(\\.\\w+)*@(\\w+\\.)+\\w{2,5})\\s*$");

            if (!r.IsMatch(m_tbEmail.Text))
            {
                m_tbHelp.Text = "邮箱格式不正确";
                return;
            }
            //一分钟发一次
            m_dtimer.Start();
            m_iNowTime = 60;
            m_btnSendEmail.IsEnabled = false;

            string paraUrlCoded = System.Web.HttpUtility.UrlEncode("Email");

            paraUrlCoded += "=" + System.Web.HttpUtility.UrlEncode(m_tbEmail.Text);
            //paraUrlCoded += "&" + System.Web.HttpUtility.UrlEncode("UserPassword");
            //paraUrlCoded += "=" + System.Web.HttpUtility.UrlEncode(GetMd5Hash(pbUserPassword.Password));
            string result = NoFileRequestUtils.NoFilePostRequest("http://www.launchpadlight.com/sharer/SendEmailValidCode", paraUrlCoded);

            if (result.Equals("success"))
            {
                //发送邮件成功,不处理
                //Console.WriteLine("发送邮箱成功");
            }
            else
            {  //发送邮箱失败
                //Console.WriteLine("发送邮箱失败");
                //弹出对话框显示原因
                System.Windows.Forms.MessageBox.Show(result);
            }
        }
コード例 #8
0
        private void UserControl_Loaded(object sender, RoutedEventArgs e)
        {
            ValidCode validCode = new ValidCode(5, ValidCode.CodeType.Alphas);

            m_iValidCode.Source = BitmapFrame.Create(validCode.CreateCheckCodeImage());
            m_sValidCode        = validCode.CheckCode;

            if (m_dtimer == null)
            {
                m_dtimer          = new System.Windows.Threading.DispatcherTimer();
                m_dtimer.Interval = TimeSpan.FromSeconds(1);
                m_dtimer.Tick    += dtimer_Tick;
            }
        }
コード例 #9
0
        /// <summary>
        /// 校验验证码
        /// </summary>
        /// <param name="smscode"></param>
        /// <param name="phonenumber"></param>
        /// <returns></returns>
        public string ValidCode(ValidCode model)
        {
            SetJsonHeader();

            var content = GetPostParameters();
            //证书的路径
            var certification = GetCertificationFilePath();
            //证书的密码
            var certificationPwd = GetCertificationPwd();

            string result = HttpAsynchronousTool.CustomHttpWebRequestPost(GetCurrentUrl(this), content, certification, certificationPwd);

            return(result);
        }
コード例 #10
0
ファイル: ForgetPwd.cs プロジェクト: James-cgf/Piano
        /// <summary>
        /// 验证码
        /// </summary>
        private void validCode()
        {
            ValidCode va = new ValidCode(4);

            string[] v  = va.color();
            string[] v1 = va.validCode();
            for (int i = 0; i < v.Length; i++)
            {
                tb[i].Text = v1[i];
                code      += v1[i];
                Color color = ColorTranslator.FromHtml(v[i]);
                tb[i].ForeColor = color;
            }
        }
コード例 #11
0
        public override int GetHashCode()
        {
            int hash = 1;

            if (header_ != null)
            {
                hash ^= Header.GetHashCode();
            }
            if (UserName.Length != 0)
            {
                hash ^= UserName.GetHashCode();
            }
            if (Password.Length != 0)
            {
                hash ^= Password.GetHashCode();
            }
            if (ValidCode.Length != 0)
            {
                hash ^= ValidCode.GetHashCode();
            }
            if (ValidId.Length != 0)
            {
                hash ^= ValidId.GetHashCode();
            }
            if (PhoneNumber.Length != 0)
            {
                hash ^= PhoneNumber.GetHashCode();
            }
            if (DeviceCode.Length != 0)
            {
                hash ^= DeviceCode.GetHashCode();
            }
            if (InviteCode.Length != 0)
            {
                hash ^= InviteCode.GetHashCode();
            }
            if (LoginType != 0)
            {
                hash ^= LoginType.GetHashCode();
            }
            if (Register != false)
            {
                hash ^= Register.GetHashCode();
            }
            if (_unknownFields != null)
            {
                hash ^= _unknownFields.GetHashCode();
            }
            return(hash);
        }
コード例 #12
0
        public async Task <IHttpActionResult> DeleteValidCode(int id)
        {
            ValidCode validCode = await db.ValidCodes.FindAsync(id);

            if (validCode == null)
            {
                return(NotFound());
            }

            db.ValidCodes.Remove(validCode);
            await db.SaveChangesAsync();

            return(Ok(validCode));
        }
コード例 #13
0
        public async Task <IHttpActionResult> PostValidCode(SendCodeByEmail Email)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            ValidCode validCode = new ValidCode();

            try
            {
                validCode.Code = RandomString(6);
                var user = userCtx.Users.First(x => x.Email == Email.Email);
                validCode.UserId = user.Id;

                db.ValidCodes.Add(validCode);
                await db.SaveChangesAsync();
            }
            catch (Exception e)
            {
                return(BadRequest(e.Message));
            }

            try
            {
                MailMessage mail   = new MailMessage("*****@*****.**", Email.Email);
                SmtpClient  client = new SmtpClient();
                client.Port = 587;
                client.UseDefaultCredentials = false;
                client.DeliveryMethod        = SmtpDeliveryMethod.Network;
                client.Host      = "smtp.gmail.com";
                client.EnableSsl = true;
                mail.Subject     = "Recuperação de senha";
                mail.IsBodyHtml  = true;
                mail.Body        = "<div>" +
                                   "<p>Olá</p>" +
                                   "<p>O código para recuperar sua senha é:</p><br/>" +
                                   "<h1>" + validCode.Code + "</h1>" +
                                   "</div>";
                client.Credentials = new System.Net.NetworkCredential("*****@*****.**", "cledsoncoords");
                client.Send(mail);
            }
            catch (Exception e)
            {
                return(BadRequest(e.Message));
            }


            return(CreatedAtRoute("DefaultApi", new { id = validCode.Id }, validCode));
        }
コード例 #14
0
ファイル: UtilityController.cs プロジェクト: 17/YunPos
        /// <summary>
        /// 验证码
        /// </summary>
        #region public ActionResult VaildCode()
        public ActionResult VaildCode()
        {
            //bool success = RedisHelper.Remove("3ahfeugdzm5uli4yrovskxnv_*");
            //bool success1 = SessionHelper.Set("Test1", "ASDFASDFASDF");
            //bool success2 = SessionHelper.Set("Test2", new { id = Guid.NewGuid(), date = DateTime.Now.AddDays(-1).ToString("yyyy-MM-dd HH:mm:ss.fff"), code = 123 });
            //string result1 = SessionHelper.Get("Test1");
            //object result11 = SessionHelper.Get<object>("Test1");
            //string result2 = SessionHelper.Get("Test2");
            //object result4 = SessionHelper.Get<object>("Test2");
            var code = Rand.RandNum(4).ToUpper();

            MemoryStream vaildCode = ValidCode.GetValidateCode(code);

            byte[] buffer = vaildCode.GetBuffer();
            vaildCode.Close();
            vaildCode.Dispose();
            return(File(buffer, "image/gif"));
        }
コード例 #15
0
        private void m_btnLogin_Click(object sender, RoutedEventArgs e)
        {
            if (m_tbUserName.Text.Equals(""))
            {
                m_tbHelp.Text = "未输入用户名";
                return;
            }
            if (m_pbPassWord.Password.Equals(""))
            {
                m_tbHelp.Text = "未输入密码";
                return;
            }

            if (m_tbValidCode.Text.ToLower().Equals(""))
            {
                m_tbHelp.Text = "未填写验证码";
                return;
            }
            else if (!m_tbValidCode.Text.ToLower().Equals(m_sValidCode.ToLower()))
            {
                m_tbHelp.Text = "验证码不正确";
                ValidCode validCode = new ValidCode(5, ValidCode.CodeType.Alphas);
                m_iValidCode.Source = BitmapFrame.Create(validCode.CreateCheckCodeImage());
                m_sValidCode        = validCode.CheckCode;
                return;
            }

            if (UserBusiness.IsSuccessLogin(lw.mw, m_tbUserName.Text, m_pbPassWord.Password))
            {
                //写入本地数据
                IniFullBusiness.WritePrivateProfileString("UserInfo", "UserName", m_tbUserName.Text, ConstantCollection.UserInfoFilePath);
                IniFullBusiness.WritePrivateProfileString("UserInfo", "PassWord", Encryption.Encode(m_pbPassWord.Password), ConstantCollection.UserInfoFilePath);
                lw.DialogResult = true;
            }
            else
            {
                //System.Windows.Forms.MessageBox.Show(result.Substring(5));
                ValidCode validCode = new ValidCode(5, ValidCode.CodeType.Alphas);
                m_iValidCode.Source = BitmapFrame.Create(validCode.CreateCheckCodeImage());
                m_sValidCode        = validCode.CheckCode;
            }
        }
コード例 #16
0
        public async Task <IHttpActionResult> CheckValidCode(GetCode Code)
        {
            try
            {
                ValidCode validCode = await db.ValidCodes
                                      .Where(x => x.Code == Code.Code)
                                      .FirstOrDefaultAsync();

                if (validCode == null)
                {
                    return(NotFound());
                }

                return(Ok(validCode));
            }
            catch (Exception e)
            {
                return(BadRequest(e.Message));
            }
        }
コード例 #17
0
        private void m_btnRegister_Click(object sender, RoutedEventArgs e)
        {
            if (m_tbUserName.Text.Equals(""))
            {
                m_tbHelp.Text = "未输入用户名";
                return;
            }
            Regex r2 = new Regex("[%--`~!@#$^&*()=|{}':;',\\[\\].<>/?~!@#¥……&*()——| {}【】‘;:”“'。,、?]");//格式 RegExp("[在中间定义特殊过滤字符]")

            if (r2.IsMatch(m_tbUserName.Text))
            {
                m_tbHelp.Text = "用户名含特殊字符";
                return;
            }

            if (m_pbPassWord.Password.Equals("") || m_pbPassWordAgain.Password.Equals(""))
            {
                m_tbHelp.Text = "未输入密码";
                return;
            }
            if (!m_pbPassWord.Password.Equals(m_pbPassWordAgain.Password))
            {
                m_tbHelp.Text = "两次密码不相同";
                return;
            }

            if (m_tbValidCode.Text.ToLower().Equals(""))
            {
                m_tbHelp.Text = "未填写验证码";
                return;
            }
            else if (!m_tbValidCode.Text.ToLower().Equals(m_sValidCode.ToLower()))
            {
                m_tbHelp.Text = "验证码不正确";
                ValidCode validCode = new ValidCode(5, ValidCode.CodeType.Alphas);
                m_iValidCode.Source = BitmapFrame.Create(validCode.CreateCheckCodeImage());
                m_sValidCode        = validCode.CheckCode;
                return;
            }

            if (m_tbEmail.Text.Length > 32)
            {
                m_tbHelp.Text = "邮箱过长";
                return;
            }
            Regex r = new Regex("^\\s*([A-Za-z0-9_-]+(\\.\\w+)*@(\\w+\\.)+\\w{2,5})\\s*$");

            if (!r.IsMatch(m_tbEmail.Text))
            {
                m_tbHelp.Text = "邮箱格式不正确";
                return;
            }
            if (!r.IsMatch(m_tbEmail.Text))
            {
                m_tbHelp.Text = "邮箱格式不正确";
                return;
            }
            if (m_tbEmailValidCode.Text.ToLower().Equals(""))
            {
                m_tbHelp.Text = "未填写邮箱验证码";
                return;
            }

            m_tbHelp.Text = "";

            string paraUrlCoded = System.Web.HttpUtility.UrlEncode("UserName");

            paraUrlCoded += "=" + System.Web.HttpUtility.UrlEncode(m_tbUserName.Text);
            paraUrlCoded += "&" + System.Web.HttpUtility.UrlEncode("UserPassword");
            paraUrlCoded += "=" + System.Web.HttpUtility.UrlEncode(Encryption.GetMd5Hash(m_pbPassWord.Password));
            paraUrlCoded += "&" + System.Web.HttpUtility.UrlEncode("UserEmail");
            paraUrlCoded += "=" + System.Web.HttpUtility.UrlEncode(m_tbEmail.Text);
            paraUrlCoded += "&" + System.Web.HttpUtility.UrlEncode("EmailValidCode");
            paraUrlCoded += "=" + System.Web.HttpUtility.UrlEncode(m_tbEmailValidCode.Text);
            string result = NoFileRequestUtils.NoFilePostRequest("http://www.launchpadlight.com/sharer/Register", paraUrlCoded);

            if (result.Equals("success"))
            {
                //Console.WriteLine("注册成功");
                System.Windows.Forms.MessageBox.Show("注册成功");
                lw.Close();
            }
            else
            {
                //弹出对话框显示失败原因
                System.Windows.Forms.MessageBox.Show(result.Substring(5));
                ValidCode validCode = new ValidCode(5, ValidCode.CodeType.Alphas);
                m_iValidCode.Source = BitmapFrame.Create(validCode.CreateCheckCodeImage());
                m_sValidCode        = validCode.CheckCode;
            }
        }
コード例 #18
0
 public void CreateImageSource()
 {
     validCode   = new ValidCode(4, ValidCode.CodeType.Numbers);
     ImageSource = BitmapFrame.Create(validCode.CreateCheckCodeImage());
 }