IT Community - Software Programming, Web Development and Technical Support

How to encrypt the passwords before saving to database in c#?

This is a discussion on How to encrypt the passwords before saving to database in c#? within the C# Programming forums, part of the Software Development category; How to encrypt the passwords before saving to database in c#?...


Go Back   IT Community - Software Programming, Web Development and Technical Support > Software Development > C# Programming

Register FAQ Members List Calendar Mark Forums Read
  #1 (permalink)  
Old 07-26-2007, 12:14 AM
itbarota itbarota is offline
D-Web Architect
 
Join Date: Jun 2007
Posts: 547
itbarota is on a distinguished road
Question How to encrypt the passwords before saving to database in c#?

How to encrypt the passwords before saving to database in c#?
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 07-26-2007, 12:19 AM
oxygen oxygen is offline
D-Web Architect
 
Join Date: Jun 2007
Posts: 633
oxygen is on a distinguished road
Default Re: How to encrypt the passwords before saving to database in c#?

Method --1
Saving an Encrypted Password to the Database
The following code customization encrypts the password before saving it into the database. Add this code to the UsersRecordControl class, located in
NET Framework 1.1:

...\<App Folder>\Users\AddUsersPage.Controls.cs or .vb

.NET Framework 2.0:

...\<App Folder>\App_Code\Users\AddUsersPage.Controls.cs or .vb

using System.Security.Cryptography;
...
public override void GetUIData()
{
base.GetUIData();
UsersRecord record = this.GetRecord();
string password = record.Password+record.UserID;
HashAlgorithm mhash = new SHA1CryptoServiceProvider();
byte[] bytValue = System.Text.Encoding.UTF8.GetBytes(password);
byte[] bytHash = mhash.ComputeHash(bytValue);
mhash.Clear();
record.Password = Convert.ToBase64String(bytHash);
}

OR
Method --2

Using the Encrypted Password when Logging into the Application:

The following code hashes the Password and UserID to create the encrypted password. It then puts this encrypted password back in to the Password text field before calling the base.login() method to complete the login process. Place this code in the SignInControl class, located in:

.NET Framework 1.1:

...\<App Folder>\Shared\SignIn_Control.Controls.cs or .vb

.NET Framework 2.0:

...\<App Folder>\App_Code\Shared\SignIn_Control.Controls.cs or .vb

using System.Security.Cryptography;
...
public override void Login(bool redirectOnSuccess)
{
string password = this.Password.Text+this.UserName.Text;
HashAlgorithm mhash = new SHA1CryptoServiceProvider();
byte[] bytValue = System.Text.Encoding.UTF8.GetBytes(password);
byte[] bytHash = mhash.ComputeHash(bytValue);
mhash.Clear();
this.Password.Text = Convert.ToBase64String(bytHash);
base.Login(redirectOnSuccess);
}
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How can we encrypt the username and password using PHP? sundarraja PHP Programming 3 05-15-2008 07:29 AM
Database space-saving functions available in php vigneshgets PHP Programming 1 01-18-2008 04:20 AM
How can I tell when Daylight Saving is in effect? itbarota HTML, CSS and Javascript Coding Techniques 1 01-01-2008 08:40 PM
What are three rule to create good passwords? vadivelanvaidyanathan Database Support 1 07-17-2007 12:41 AM
Taking Snapshot and saving image clipping in flash oxygen Flash Actionscript Programming 0 07-17-2007 12:12 AM


All times are GMT -7. The time now is 11:30 PM.


Copyright ©2004 - 2007, DiscussWeb. All Rights Reserved.

SEO by vBSEO 3.0.0