Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6616653
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T20:36:32+00:00 2026-05-25T20:36:32+00:00

I already got my password encrypted and store it in database but now I

  • 0

I already got my password encrypted and store it in database but now I want to compare the encrypted value to the password that a user type upon loading a page. Consider this code:

string userName = txtusername.Text;
string password = txtpassword.Text;
Encryptor en = new Encryptor(EncryptionAlgorithm.Rc2, CreateRandomPassword(7));
password = en.Encrypt(password);            
DataTable dt = uMManager.ValidateUser(userName, password);

CreateRandomPassword Method

private static string CreateRandomPassword(int passwordLength)
{
  string allowedChars = "abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNOPQRSTUVWXYZ0123456789!@$?_-";
  char[] chars = new char[passwordLength];
  Random rd = new Random();

  for (int i = 0; i < passwordLength; i++)
  {
     chars[i] = allowedChars[rd.Next(0, allowedChars.Length)];
  }
  return new string(chars);
}

Encryptor Class

public class Encryptor
    {
        EncryptEngine engin;
        public byte[] IV;

        public Encryptor(EncryptionAlgorithm algID, string key)
        {
            engin = new EncryptEngine(algID, key);
        }

        public EncryptEngine EncryptEngine
        {
            get
            {
                return engin;
            }
            set
            {
                engin = value;
            }
        }

        public string Encrypt(string MainString)
        {
            MemoryStream memory = new MemoryStream();
            CryptoStream stream = new CryptoStream(memory, engin.GetCryptTransform(), CryptoStreamMode.Write);
            StreamWriter streamwriter = new StreamWriter(stream);
            streamwriter.WriteLine(MainString);
            streamwriter.Close();
            stream.Close();
            IV = engin.Vector;
            byte[] buffer = memory.ToArray();
            memory.Close();
            return Convert.ToBase64String(buffer);

        }
    }

I made a local method to generate random string for RC2 encryption. EncryptionAlgorithm is a Enums for the types of encryption.
Now how can I compare ‘password’ to the password field in my database to check if the credential is correct

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T20:36:32+00:00Added an answer on May 25, 2026 at 8:36 pm

    You can’t check if the credential is correct, since you’ve encrypted it with a key you’ve thrown away. If you store the key along with the password, the encryption serves no purpose. If you don’t, you can’t verify.

    Instead of trying to create a new way to store passwords, why not use one of the ways that’s known to work?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've already got a NAnt build script that builds/runs tests/zips web project together, etc.
I'm setting up a Jabber server for my website. I've already got some user
Already finished implementing the player. I want to implement the progress bar. But I
I've got a WPF windows client that calls a WCF web service. The user
I'm working on a PHP page that allows the user to reset their password.
I just got put in charge of a new app, one that is already
We've got an existing ASP.NET web application that already uses a home-grown role based
On my website that I'm developing I've already got all my login sorted, and
I got an interesting error which says that headers were already sent through ob_end_flush();
I've already got my custom header drawing in my GridView using SetRenderMethodDelegate on the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.