public void validatecode()
        {
            ImageValidate sc           = new ImageValidate();
            string        SecurityCode = sc.GetSecurityCode(6);

            Session["ValidateCode"] = SecurityCode.ToLower();
        }
 public ActionResult Create(Medicine medicine, HttpPostedFileBase file)
 {
     try
     {
         IBL bl = new BL.BL();
         if (file == null)
         {
             bl.AddMedicine(medicine);
             return(RedirectToAction("Index"));
         }
         GoogleDriveAPIHelper googleDrive = new GoogleDriveAPIHelper();
         googleDrive.UploadFileOnDrive(file);
         medicine.ImagePath = googleDrive.DownloadGoogleFileByName(file.FileName);
         ImageValidate imageValidate = new ImageValidate();
         bool          result        = true;
         if (medicine.ImagePath != null)
         {
             result = imageValidate.Validate(medicine.ImagePath);
         }
         if (result)
         {
             medicine.ImagePath = $"/GoogleDriveFiles/{file.FileName}";
             //add image to drive
             bl.AddMedicine(medicine);
         }
         else
         {
             Session["Error"] = "This image isn't valid";
             return(View("AddImage", new MedicineViewModel(medicine)));
         }
         return(RedirectToAction("Index"));
     }catch (Exception e) { return(View()); }
 }
        public ActionResult FindPassword(FindPassword formValues)
        {
            if (User.Identity.IsAuthenticated)
            {
                return(RedirectToAction("index"));
            }

            if (ModelState.IsValid)
            {
                var emailReg = new System.Text.RegularExpressions.Regex("^(\\w)+(\\.\\w+)*@[\\w\\d]+((\\.\\w+)+)$");
                if (formValues.UserEmail == null || !emailReg.IsMatch(formValues.UserEmail))
                {
                    ModelState.AddModelError("UserEmail", "邮箱格式不正确");
                    return(View(formValues));
                }
                else if (Session["ValidateCode"] == null ||
                         formValues.ValidateCode == null ||
                         formValues.ValidateCode.ToLower() != Session["ValidateCode"].ToString().ToLower())
                {
                    ModelState.AddModelError("ValidateCode", "验证码错误");
                    return(View(formValues));
                }

                UserModel userModel = new UserModel();
                user_info userInfo  = userModel.GetUserInfo(formValues.UserEmail);
                string    newPwd    = ImageValidate.CreateCode(6);//生生6位数的随机密码
                userInfo.ui_password = userModel.PasswordEncrypt(newPwd);
                userModel.Save();
                //发送新密码
                MeetingCanlendar.Tools.SendEmail.ResetPassword(formValues.UserEmail, newPwd);
            }

            return(RedirectToAction("FindPassword", new { step = 2 }));
        }
        public FileResult GetImageValidate()
        {
            string validateStr = ImageValidate.CreateCode(4);

            Session["ValidateCode"] = validateStr;

            Response.ContentType = "image/jpeg";
            return(new FileStreamResult(ImageValidate.CreateImage(validateStr), Response.ContentType));
        }
Example #5
0
        private void btnGo_Click(object sender, EventArgs e)
        {
            bool VerifyResult;
            bool goVerify;

            double psnr;

            string  vFileName;
            TextBox tb;


            vFileName = Path.GetFileNameWithoutExtension(this.tbPath1.Text) + "-V" + Path.GetExtension(this.tbPath1.Text);

            VerifyResult = true;
            goVerify     = File.Exists(vFileName);
            if (goVerify)
            {
                tb      = new TextBox();
                tb.Text = vFileName;
                this.LoadSource(tb);
            }

            if (this.pbSource.Image == null)
            {
                this.btnOpenS_Click(sender, e);
            }

            if (this.pbSource.Image == null)
            {
                return;
            }

            if (goVerify)
            {
                Image img;

                img                 = this.pbTarget.Image;
                VerifyResult        = ImageValidate.Verify(this.pbSource.Image, ref img);
                this.pbTarget.Image = img;
            }
            else
            {
                this.pbTarget.Image = ImageValidate.MakeVerifiable(this.pbSource.Image);

                this.pbTarget.Image.Save(
                    vFileName
                    , ((this.pbSource.Image.RawFormat.Guid == ImageFormat.MemoryBmp.Guid) ? ImageFormat.Bmp : this.pbSource.Image.RawFormat));
            }

            this.tbTarget.Text = ""
                                 + "Width: " + this.pbTarget.Width.ToString() + "\r\n"
                                 + "Height: " + this.pbTarget.Height.ToString() + "\r\n"
                                 + "Format: " + this.GetImageFormat(this.pbTarget.Image);

            if (goVerify)
            {
                this.tbTarget.Text += "\r\n\r\n"
                                      + "Verify: " + VerifyResult.ToString();
            }

            psnr = Quality.PSNR(this.pbSource.Image, this.pbTarget.Image);
            if (Double.IsNaN(psnr))
            {
                this.tbTarget.Text += "\r\n\r\n"
                                      + "Images are identical.";
            }
            else
            {
                this.tbTarget.Text += "\r\n\r\n"
                                      + "PSNR: " + psnr.ToString("00.0000");
            }
        }