如何确定用户输入的密码是对还是错? [英] How can i determine whether the password entered by user is right or wrong ?

查看:83
本文介绍了如何确定用户输入的密码是对还是错?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何确定用户输入的密码在程序中是对还是错?通常,如果输入了错误的密码,则会创建一个包含垃圾数据的文件.

这是代码-

How can i determine whether the password entered by user is right or wrong in program ? Generally when wrong password is entered a file with garbage data is created.

Here''s the code -

private void DecryptFile(string inputFile2, string outputFile2)
   {

       try
       {
           string password = password2;      // password2 is data coming through textbox

           System.Text.UnicodeEncoding UE = new System.Text.UnicodeEncoding();
           byte[] key = UE.GetBytes(password);

           FileStream fsCrypt = new FileStream(inputFile2, FileMode.Open);


           RijndaelManaged RMCrypto = new RijndaelManaged();

           RMCrypto.Padding = PaddingMode.None;


           CryptoStream cs = new CryptoStream(fsCrypt, RMCrypto.CreateDecryptor(key, key), CryptoStreamMode.Read);

           FileStream fsOut = new FileStream(outputFile2, FileMode.Create);

           int data;

           while ((data = cs.ReadByte()) != -1)

           fsOut.WriteByte((byte)data);

               fsOut.Close();
               cs.Close();
               fsCrypt.Close();
                return;


       }

       catch(Exception e)
       {
           MessageBox.Show("Your password does not match"+e.Message);
           DeLoadImage_tbx.Text = "";  //Stegno image
           DeSaveFile_tbx.Text = "";   // Location to save data file
           textBox3.Text = "";        // textbox control for accepting password

       }

   }

   }

推荐答案

这意味着这是您输入错误密码时遇到的错误.有什么问题?捕获此异常并报告密码错误.
This means that this is the error you get when you enter a wrong password. What is the issue ? Catch this exception and report that the password was wrong.


这篇关于如何确定用户输入的密码是对还是错?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆