473,406 Members | 2,369 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

password hash

I have been asked to rewrite some apps that contain databases of
username and passwords to store the passwords as hashes. Getting the
data into a hash format is no problem. however, how do I go about
reading the hash value to validate a user? Is there a method of the
FormsAuthentication class for doing this?
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 16 '05 #1
2 3145
Phil,

There is nothing on the FormsAuthentication class that will help you
with this. Generally, you are hooking into that in order to be called when
you want to provide custom authentication. .NET 2.0 (particularly ASP.NET)
has a ton of new classes to help with authentication (which you might be
able to use).

Basically, what you need to do is hash the password that comes in, and
compare it to wherever you store the hash. If you are using one of the
algorithms represented in the System.Security.Cryptography namespace, then
your task should be easy.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Phil Townsend" <ph*******@yahoo.com> wrote in message
news:uA**************@TK2MSFTNGP12.phx.gbl...
I have been asked to rewrite some apps that contain databases of
username and passwords to store the passwords as hashes. Getting the
data into a hash format is no problem. however, how do I go about
reading the hash value to validate a user? Is there a method of the
FormsAuthentication class for doing this?
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 16 '05 #2
I would use at least a keyed hash such as HMACSHA1 and use the full
resulting hash size to store in the db.
How you get and set values to your DB depends on your needs. You could use
sql, and xml file, txt/csv/tsv (e.g. good ol unix style.)

// Your PW system. Use at least a "keyed" hash.
byte[] key = Encoding.UTF8.GetBytes("my key"); // Use same each time, but
hide.
HMACSHA1 hmac = new HMACSHA1(key);

// Enter Password into db.
string userPW = "letmein";
byte[] pwBytes = Encoding.UTF8.GetBytes(userPW);
byte[] pwHash = hmac.ComputeHash(pwBytes);
// Store pwHash with User's Record in db.

// Verify Password.
byte[] storedHash = pwHash; // TODO: Get pw hash bytes from DB.
string enteredPW = "nogo";
byte[] newHash = hmac.ComputeHash(Encoding.UTF8.GetBytes(enteredPW) );

if ( BuffersEqual(storedHash, newHash) )
Console.WriteLine("Password valid.");
else
Console.WriteLine("Invalid password.");
public static bool BuffersEqual(byte[] a1, byte[] a2)
{
if ( a1 == null || a2 == null )
throw new ArgumentNullException("null parm.");
if ( a1.Length != a2.Length )
return false;
Console.WriteLine("Hash1:"+BitConverter.ToString(a 1));
Console.WriteLine("Hash2:"+BitConverter.ToString(a 2));
for(int i=0; i < a1.Length; i++)
{
if ( a1[i] != a2[i] )
return false;
}
return true;
}

--
William Stacey, MVP
http://mvp.support.microsoft.com

"Phil Townsend" <ph*******@yahoo.com> wrote in message
news:uA**************@TK2MSFTNGP12.phx.gbl...
I have been asked to rewrite some apps that contain databases of
username and passwords to store the passwords as hashes. Getting the
data into a hash format is no problem. however, how do I go about
reading the hash value to validate a user? Is there a method of the
FormsAuthentication class for doing this?
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!


Nov 16 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

14
by: Todd Johnson | last post by:
I am creating a dialog in wxPython for log in purposes. Basically when the user clicks the ok button, the dialog box saves the user name and password as class attributes. Then as long as the...
0
by: aars | last post by:
Hello all, I am creating a user administration system where system administrator can activate services for a user, like webspace, a mail account or a subdomain. I now want to create a...
27
by: frizzle | last post by:
Hi there, I've read in a few places that you should *never* store original passwords in a mySQL DB. Now i wonder if you encrypt it (with MD5 ?), how should i create a lost password function,...
7
by: jrefactors | last post by:
I want to ask how password is stored and how to check the authentication? I have heard password is never encrypted and decrypted, but it is hashed. For example, consider a simple email logon...
36
by: dcrespo | last post by:
Hi all, I have a program that serves client programs. The server has a login password, which has to be used by each client for logging in. So, when the client connects, it sends a string with a...
4
by: PJones | last post by:
I am looking for the best way to one way encrypt a password for storage in a database using (asp.net / vb.net) basically I need some functions or examples that I can freely use in a commercial...
26
by: David Garamond | last post by:
I read that the password hash in pg_shadow is salted with username. Is this still the case? If so, since probably 99% of all PostgreSQL has "postgres" as the superuser name, wouldn't it be better...
21
by: solomon_13000 | last post by:
I am using ms access database and asp 3.0 as my front end. In my database there is a table called account and a field called password. How do I protect the password stored in the database.
3
by: phforum | last post by:
I have no ideas to encrypt the user input password from the text box.....
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.