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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T01:34:58+00:00 2026-05-27T01:34:58+00:00

I am trying to create a basic WPF application that can store an encrypted

  • 0

I am trying to create a basic WPF application that can store an encrypted password in SQL Server 2008 and also retrieve back the password when the user tries to login but I am getting an error after following this article

http://www.dreamincode.net/forums/topic/123865-one-way-encryption/

I read thru rainbow attacks and salting and hashing..

I tried some code but getting an error

The error I am getting is

string or binary data would be truncated

I read this article and tried to convert the textbox.text to string and also tried typing only one alphabet in the password texbox but still does not work (“I changed the connstring for security reasons as the connstring is working and there is no problem with that”)

private void button1_Click(object sender, RoutedEventArgs e)
{
        string strPassword;
        SqlConnection cs= new SqlConnection("Data Source=STEVEJOBS;Initial Catalog=Test database;Integrated Security=True");
        SqlDataAdapter da = new SqlDataAdapter();
        da.InsertCommand = new SqlCommand("INSERT INTO Member_info(Name,Username,Password,Email,Member) VALUES(@Name,@Username,@Password,@Email,@Member)", cs);
        da.InsertCommand.Parameters.Add("@Name", SqlDbType.NVarChar).Value = Name_tb.Text;
        da.InsertCommand.Parameters.Add("@Email", SqlDbType.VarChar).Value = Email_tb.Text;
        da.InsertCommand.Parameters.Add("@Username", SqlDbType.VarChar).Value = Username_tb.Text;

        //MD5CryptoServiceProvider md5Hasher = new MD5CryptoServiceProvider();
        //byte[] hashedBytes;
        //UTF8Encoding encoder = new UTF8Encoding();
        //hashedBytes = md5Hasher.ComputeHash(encoder.GetBytes(strPassword));
        //SqlParameter paramPwd;
        //paramPwd = new SqlParameter("@Password", SqlDbType.Binary, 16);
        //paramPwd.Value = hashedBytes;
        //da.InsertCommand.Parameters.Add(paramPwd);

        da.InsertCommand.Parameters.Add("@Password", SqlDbType.VarChar).Value = HashPassword(Password_tb.Text.ToString());
        da.InsertCommand.Parameters.Add("@Member", SqlDbType.NText).Value =Myes_rb.Content ;

        cs.Open();

        da.InsertCommand.ExecuteNonQuery();

        cs.Close();
        MessageBox.Show("Sucessfully added");
    }

    static string HashPassword(string pasword)
{
           byte[] arrbyte = new byte[pasword.Length];
           SHA256 hash = new SHA256CryptoServiceProvider();
           arrbyte = hash.ComputeHash(Encoding.UTF8.GetBytes(pasword));
           return Convert.ToBase64String(arrbyte);
    }

Thks for the help!

  • 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-27T01:34:59+00:00Added an answer on May 27, 2026 at 1:34 am

    This error appears when you try to insert a string with more characters than specified in column definition. Make your string columns wider.

    To identify column that triggers this error, You can change your INSERT statement by eliminating parameters one by one (remove da.InsertCommand.Parameters.Add line for that column and in VALUES part of INSERT statement put a constant like ‘John’).

    EDIT#1:

    Continue eliminating columns one by one (just like You did with password column) and once insert statement doesn’t fail, You will know what column caused error. Then debug to find out the length of value you are assigning to (failing) column parameter. Length of that column in database must be >= than length of value You are trying to insert.

    Another thing to note: at the time of writing your question, You thought that password column is problem, but maybe some other column is problem. And only solution to this error is to make all columns wide enough so values can be stored in them.

    EDIT#2:

    Use Password property to get text user typed in:

        da.InsertCommand.Parameters.Add("@Password", SqlDbType.VarChar).Value = 
            HashPassword(Password_tb.Password);
    

    To get the length of hashed password use this code instead:

        string pwdHash = HashPassword(Password_tb.Password);
        da.InsertCommand.Parameters.Add("@Password", SqlDbType.VarChar).Value = pwdHash;
    

    Put breakpoint on the second line and check the length of pwdHash string. Password column in database table must be equal or greater to this length.

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

Sidebar

Related Questions

I am trying to create a WPF application that will be a central point
I'm trying to create a basic system that will allow only specific users to
I am trying create a WCF service that leverages the WPF MediaPlayer on the
I am trying to create a basic datasheet in my application using a TableLayout.
I have a C#/WPF app. I am trying to create different versions that will
I am trying to create a super basic consol application why does the consol
i'm trying to create basic application on Play Frramework(1.2.2) + siena (2.0.2) + crudsiena(2.0.1)
I'm trying to create a basic application, i created facebook application before but everything
I am trying to create a second thread with dispatcher so that I can
I'm trying to create a basic HTTP server to learn more about how it

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.