DEV Community

vblover programmer
vblover programmer

Posted on

C#: Secure Password

SecurePassword Class:

using System;
using System.Text;
using System.Security.Cryptography;
namespace UserAccountSystem.Class
{
   public static class SecurePassword
    {
       public static String GetMd5Hash(String input)
    {
        MD5 md5Hasher = MD5.Create();
        byte[] data = md5Hasher.ComputeHash(Encoding.Default.GetBytes(input));
         StringBuilder sBuilder = new StringBuilder();
         for (int i = 0; i < data.Length ; i++)
         {
             sBuilder.Append(data[i].ToString("x2"));
         }
        return sBuilder.ToString();
    }
       public static bool verifyMd5Hash(String input, String hash) 
     {
         String hashOfInput = GetMd5Hash(input);
         StringComparer comparer= StringComparer.OrdinalIgnoreCase;
         if (hashOfInput.CompareTo(hash) == 0) {
         return true;
         }
         return false;
     }
    }
}

Enter fullscreen mode Exit fullscreen mode

Using for password property to save:

public String Password()
        { return Class.SecurePassword.GetMd5Hash(this.ConfirmPasswordBox.Value); }

Enter fullscreen mode Exit fullscreen mode

check for password correction:

if (Class.SecurePassword.verifyMd5Hash(this.PasswordBox.Value,UserAccount.TableAdapter.GetPassword(this.ID)) == false)
                    {
                        this.PasswordBox.Value = "";
                        this.ConfirmPasswordBox.Value = "";
                        errorProvider1.SetError(this.PasswordBox, "Wrong Password!");
                        this.PasswordBox.Focus();
                        this.PasswordBox.Select();
                        return; 
                    }

Enter fullscreen mode Exit fullscreen mode

Image of AssemblyAI tool

Challenge Submission: SpeechCraft - AI-Powered Speech Analysis for Better Communication

SpeechCraft is an advanced real-time speech analytics platform that transforms spoken words into actionable insights. Using cutting-edge AI technology from AssemblyAI, it provides instant transcription while analyzing multiple dimensions of speech performance.

Read full post

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Engage with a sea of insights in this enlightening article, highly esteemed within the encouraging DEV Community. Programmers of every skill level are invited to participate and enrich our shared knowledge.

A simple "thank you" can uplift someone's spirits. Express your appreciation in the comments section!

On DEV, sharing knowledge smooths our journey and strengthens our community bonds. Found this useful? A brief thank you to the author can mean a lot.

Okay