Data Encryption-remember passwords, automatic logon, and encryption-save data using a mix of DES and MD5, desmd5

Source: Internet
Author: User

Data Encryption-remember passwords, automatic logon, and encryption-save data using a mix of DES and MD5, desmd5

Introduction to MD5: MD5 is the Message-Digest Algorithm 5 (Information-Digest Algorithm 5), used to ensure the integrity and consistency of information transmission. It is one of the widely used Hash Algorithms in computers (also translated digest algorithms and hash algorithms). mainstream programming languages generally have MD5 implementations. Computation of data (such as Chinese characters) into another fixed length value is the basic principle of the hash algorithm. The predecessor of MD5 is MD2, MD3, and MD4.

The MD5 algorithm has the following features:
1. Compression: Data of any length, the calculated MD5 value length is fixed.
2. Easy Calculation: it is easy to calculate the MD5 value from the original data.
3. Anti-modification: Any modification to the original data, even if only one byte is modified, the MD5 value obtained is very different.
4. Strong anti-collision: it is very difficult to find a data with the same MD5 value (that is, forged data) because the original data and its MD5 value are known.

Note: MD5 is often used for password encryption.

Practical Application: In the wpf project, MD5 should be used to encrypt sensitive data and store the data in the database. Remember the password again. MD5 cannot be decrypted irreversible, but remember that the password is saved to the local file as ciphertext, remember the password and then log on again, you need to decrypt the Password box assigned to the current interface, and then click Login to encrypt and compare it with the database, in this way, you cannot use MD5 to remember the password. Here, we need to use DES to remember to save the password locally. When logging on, we can obtain the remembered Information DES for decryption. Click login and then perform MD5 encryption.

Implementation Process:

Obtain interface logon information

// Obtain the logon information loginRecord. name = tbName. text. trim (); loginRecord. MD5Pwd = TrialHelper. getMD5 (tbPwd. password); // the MD5 mode loginRecord for saving to the database. pwd = TrialHelper. encryptDES (tbPwd. password); // remember the Password in des mode and save it to the local loginRecord. isSavePwd = (bool) cbSaveName. isChecked; loginRecord. isAutoLogin = (bool) cbAutoLogin. isChecked;

Achieve Logon

// Use MD5 encryption to log on to LoginService. LoginInfo lgInfo = LoginService. LoginService. GetLoginUserInfo (loginRecord. Name, loginRecord. MD5Pwd );

After logging on, remember the password to save the account information to the local file.

// After Successful Logon, save the configuration file XmlHelper. XmlSerializeToFile (loginRecord, "LoginInfo. ini ");

Remember the Password Logon mode and automatic logon mode, read the account information from the configuration file and assign values to the interface, and click the logon logic. The MD5 encryption is used to log on to the database and compare it with the ciphertext in the database.

// Obtain the logon configuration information and assign values to the interface. The password recorded by LoginInfo is encrypted loginRecord = XmlHelper. XmlDeserializeFromFile <LoginRecord> ("LoginInfo. ini"); if (loginRecord! = Null) {tbName. text = loginRecord. name; // the user Name input box is assigned tbPwd. password = TrialHelper. decryptDES (loginRecord. pwd); // value assigned to the password input box. The decrypted value of Des is cbAutoLogin. isChecked = loginRecord. isAutoLogin; // select the cbSaveName option for automatic logon. isChecked = loginRecord. isSavePwd; // if (loginRecord. isAutoLogin) // Automatic Logon {btnLogin_Click (null, null );}}

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.