Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I get PasswordHash value?

Status
Not open for further replies.

thedougster

Programmer
Jan 22, 2009
56
US
When I try to save a new (inserted) record via the following code:

DataRow row = dataTable.Rows [currRec];

// update data in DataSet from data entry WinForm
row.BeginEdit ();
row ["Title"] = txtTitle.Text;
row ["FirstName"] = txtFirstName.Text;
row ["MiddleName"] = txtMiddleName.Text;
row ["LastName"] = txtLastName.Text;
row ["Suffix"] = txtSuffix.Text;
row ["Phone"] = txtPhone.Text;
row ["EmailAddress"] = txtEmailAddress.Text;
row.EndEdit ();

try
{
dataAdapter.Update (dataSet, "Person.Contact");
}
catch (System.Runtime.InteropServices.ExternalException exc)
{
MessageBox.Show (exc.Message);
}

I get the following exception message:

Cannot insert the value NULL into column 'PasswordHash', table 'AdventureWorks.Person.Contact'; column does not allow nulls. INSERT fails. The statement has been terminated.

How do I get an appropriate PasswordHash value that I can put it in the newly-created record I'm inserting into the database?

For what it’s worth, the environment I’m working in is:

32-bit
SQL Server 2008 Express with Advanced Services
database:SQL2008 AdventureWorks (schema.table: Person.Contact)
SQL Server 2008 Management Studio Express
Visual C# 2008 Express
 
You can use the HASHBYTES function to get a hash to the string of the password. Just decide what hash algorithm you want to use. MD5 is the most common.

Code:
SELECT HASHBYTES('MD5', 'YourPassword')

Denny
MVP
MCSA (2003) / MCDBA (SQL 2000)
MCTS (SQL 2005 / SQL 2008 Implementation and Maintenance / Microsoft Windows SharePoint Services 3.0: Configuration / Microsoft Office SharePoint Server 2007: Configuration)
MCITP Database Admin (SQL 2005/2008) / Database Dev (SQL 2005)

My Blog
 
mrdenny:

I'm in the dark about this whole PasswordHash business. Why do individual rows in a database table have different password hashes? Isn't the password for the whole database? Please expand on this briefly, and tell me how to use HASHBYTES. Yes, I'll research it tomorrow (it's now LATE Saturday night), but give me a point of departure for my research. Thanks.
 
I would assume that each individual person has different password.
 
No, the passwordHash isn't for the database. It is for each user's login to the AdventureWorks application or website which uses that table to hold the usernames and passwords to grant access to the website.

SQL Server databases don't have passwords.

Denny
MVP
MCSA (2003) / MCDBA (SQL 2000)
MCTS (SQL 2005 / SQL 2008 Implementation and Maintenance / Microsoft Windows SharePoint Services 3.0: Configuration / Microsoft Office SharePoint Server 2007: Configuration)
MCITP Database Admin (SQL 2005/2008) / Database Dev (SQL 2005)

My Blog
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top