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 6174479
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T23:45:39+00:00 2026-05-23T23:45:39+00:00

what i am trying to do is when a user registers the password gets

  • 0

what i am trying to do is when a user registers the password gets encrypted, and the encrypted password gets saved in a database, and when the user logs in it should then decrypt the password to compare if the user entered the correct password, but when i try to decrypt its gives me a “Bad data” exception.

Please help guys.
Here is my code:

protected void btnLogin_Click(object sender, EventArgs e)
{
    try
    {
        private Cryptography crypt = new Cryptography();
        var registerUser = new test.Model.User();
        registerUser.EmailAddress = txtEmail.Text;
        registerUser.Password = txtPassword.Text;
        //new test().Getbyusername(registerUser);
        new test().getbyemail(registerUser, crypt);
    }
    catch (Exception ex)
    {

    }
}

public void getbyemail(User user, Cryptography crypt)
{
    try
    {
        var repo = new UserRepository();
        var test = repo.GetEncryptedPasswrd(user);
        var o = repo.getPrivateKey(user.EmailAddress);
        crypt.privateKey = o;
        var j = repo.getpublicKey(user.EmailAddress);
        crypt.publicKey = j;
        decryptPassword(test, o, crypt);

    }
    catch (Exception ex)
    {

    }
}

public String decryptPassword(byte [] encryptedpassword, string privateKey, Cryptography cry)
{
    decrypted = cry.decrypt(encryptedpassword, privateKey);
   //return Encoding.ASCII.GetString(decrypted);
    return Encoding.ASCII.GetString(decrypted);

}

protected void btnRegister_Click(object sender, EventArgs e)
{
    Cryptography crypt = new Cryptography();
    var registerUser = new test.Model.User();
    registerUser.Name = txtName.Text;
    registerUser.Surname = txtSurname.Text;
    registerUser.EmailAddress = txtEmailAddress.Text;
    registerUser.Password = txtPassword.Text;
    registerUser.DateRegisterd = DateTime.Now;
    new test().RegisterUser(registerUser, crypt.privateKey, crypt.publicKey,crypt, encrypted);
}

public void RegisterUser(User user, string privateKey, string publicKey, Cryptography crypt, byte[] encrypted)
{
    try
    {
        var repo = new UserRepository();
        byte[] plainText = Encoding.ASCII.GetBytes(user.Password);
        encrypted = crypt.encrypt(plainText, crypt.publicKey);
        user.Password = Encoding.ASCII.GetString(encrypted);
        user.PrivateKey = crypt.privateKey;
        user.PublickKey = crypt.publicKey;
        repo.Add(user);
    }
    catch (Exception ex)
    {

    }
}

Thanks in advance.

  • 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-23T23:45:40+00:00Added an answer on May 23, 2026 at 11:45 pm

    As said above comment you should really hash it .

    Still if you want to encrypt as you example don’t decrypt password . Instead you should encrypt password from user and simply compare to database .

    You can Consider this simple option to hash the password . http://davidhayden.com/blog/dave/archive/2004/02/16/157.aspx .

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

Sidebar

Related Questions

Rails 2.3.11 I'm trying to send an activation-style email whenever a user registers. The
I'm trying to save a logged in user's score to my sql database. I
Is there a way to use a credential coming from the user's saved password
I'm trying to user Facebooker to publish stories to Facebook. When a user submits
I'm currently trying to user actionlink helpers in a way that I don't think
what happens if an user trying to read HttpContext.Current.Cache[key] while the other one trying
I am a noob Perl user trying to get my work done ASAP so
I'm a Git user trying to use Mercurial. Here's what happened: I did a
Trying to alert user when internet is unavailable (and retry when they dismiss message).
I am trying to validate user id's matching the example: smith.jack or smith.jack.s In

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.