本文介绍了如何确定用户输入的密码是对还是错?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我如何确定用户输入的密码在程序中是对还是错?通常,如果输入了错误的密码,则会创建一个包含垃圾数据的文件.
这是代码-
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
}
}
}
推荐答案
这篇关于如何确定用户输入的密码是对还是错?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!