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#?...
| |||||||
| Register | FAQ | Members List | Calendar | Mark Forums Read |
| |||
| 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); } |
![]() |
| Thread Tools | |
| Display Modes | |
| |
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 |