Windows Forms: How to encrypt a password in C#
By FoxLearn 6/2/2017 10:23:28 PM 13.31K
How to encrypt a password using MD5 encryption in C#
Step 1: Click New Project, then select Visual C# on the left, then Windows and then select Windows Forms Application. Name your project "EncryptPassword" and then click OK
Step 2: Design your form as below
Step 3: Add code to handle your form as below
using System; using System.Text; using System.Windows.Forms; using System.Security.Cryptography; namespace EncryptPassword { public partial class Form1 : Form { public Form1() { InitializeComponent(); } static string Encrypt(string value) { //Using MD5 to encrypt a string using (MD5CryptoServiceProvider md5 = new MD5CryptoServiceProvider()) { UTF8Encoding utf8 = new UTF8Encoding(); //Hash data byte[] data = md5.ComputeHash(utf8.GetBytes(value)); return Convert.ToBase64String(data); } } private void btnEncrypt_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(txtPassword.Text)) { MessageBox.Show("Please enter your password.", "Message", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } txtResult.Text = Encrypt(txtPassword.Text); } } }
VIDEO TUTORIALS
- Windows Forms: Text to speech in C#
- Windows Forms: Print Picture Box in C#
- Windows Forms: Advanced Filter DataGridView in C#
- Windows Forms: Progress Bar in C#
- How to create a Lucky Draw games in C#
- Windows Forms: Youtube Search with Paging in C#
- Windows Forms: How to Create a Random Password Generator in C#
- Windows Forms: Tag Control in C#
Categories
Popular Posts
Visual Studio: Auto increment version
04/01/2024
What is ARM architecture?
04/01/2024