|
It's often useful for applications to encrypt data before saving it to the database. Such a situation
occurs when adding a new user record, and for security reasons, you do not want their password to be readable
directly from the database.
In this example, we encrypt and decrypt data using the .NET Hash() function to encrypt the password data.
Of course, you could use any encryption method you wish instead of the Hash() function. When a user logs
in, we hash the password value and compare the hashed password to the encrypted password in database. They
will match when user provides a correct password, and the user is allowed to log in.
Our hask key is a concatenation of the Password and UserID fields. Using two data elements lessens the
chances of producing identical encrypted passwords if two users have the same password, thereby increasing
our level of security. Our example also assumes a Users table in our database and the Users table contains
at least two fields: UserID and Password.
|