Home > SOA Tips > .NET Developer > Custom authentication scheme in .NET
SOA Tips:
EMAIL THIS
 TIPS & NEWSLETTERS TOPICS 

.NET DEVELOPER

Custom authentication scheme in .NET


Enrico Sabbadin
05.04.2004
Rating: -3.50- (out of 5)


Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us   



.NET Developer Tip
(Receive this column in your inbox,
click Edit your Profile to subscribe.)

Custom authentication scheme in .NET

Using the method of security based on .NET identity and principal objects might require you to develop some custom authentication schemes. In this tip provided by InformIT, Enrico Sabbadin examines how and why to use hashing to protect passwords used for authentication in the .NET framework.


In a custom authentication scheme, the application is responsible for matching the user-provided credentials (in the form of a username password pair) against the ones maintained in some kind of store.

The proper maintenance of the store containing such username and password info is crucial. For better security you shouldn't store passwords in plain text or in an encrypted form: Passwords' hashes should be persisted instead. Are you asking yourself how you can authenticate without knowing the password? Here is the way it works: In the authentication phase, the user-provided password is hashed on the client machine, and the result is sent to the authentication authority. The authentication authority matches the received hash with the one picked up from the user store. If the two match, the login is successful. As you can see, this approach has actually two benefits:

  • The passwords are not stored in clear text or in an encrypted form (so you don't have to worry about keeping the encryption key secret and protected).
  • The password is never transmitted over the wire, in plain text, or encrypted, so sniffing techniques are much less effective.

Note, however, that this authentication scheme is vulnerable to brute force and dictionary attacks. If a hacker sniffs a username password hash pair over the network, he or she can obtain the password in the following way:

  • Produce the hash of a word generated randomly or from a dictionary.
  • Compare the hash with the sniffed hash.
  • If the generated hash matches the sniffed password hash, the password has been cracked (otherwise, begin again).

Given enough time and computer power, the hacker will find the correct word. To alleviate the vulnerability to dictionary and brute force attacks, there are basically two techniques (that can be applied concurrently). The first consists of enforcing a password complexity policy; the second (which is effective only against dictionary attacks) consists of attaching a random generated value (a salt) to the password before hashing it. In this technique, the salt must be stored in the user store as well.

The .NET Framework comes with a full set of cryptographic libraries, so you have different ways to generate the hash from a password. The one I like most is using the static FormsAuthentication.HashPasswordForStoringInConfigFile method, which accepts as input the string to be hashed and the hashing algorithm to use (SHA1 or MD5). This method returns the hashed data in string form, thus avoiding the annoyance of dealing with the byte arrays that other .NET cryptographic libraries require. Using this method, the generation of a password hash (using a salt) is really a snap, as shown in the example below.

private static string CreatePasswordHash(string pwd, string salt) {
 string saltAndPwd = String.Concat(pwd, salt);
 string hashedPwd = 
   FormsAuthentication.HashPasswordForStoringInConfigFile(
   saltAndPwd, "SHA1");
 return hashedPwd;
}

I won't go into further details about authentication routines because the MSDN library provides two articles showing, step by step, how to develop a custom authentication mechanism against SQL Server Database or Active Directory.


Read more about custom and hybrid authentication at InformIT.


Rate this Tip
To rate tips, you must be a member of SearchSOA.com.
Register now to start rating these tips. Log in if you are already a member.




Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us   



RELATED CONTENT
SOA and Identity management
JBoss, CA Wily moves target SOA performance management
Weak encryption creates SOA vulnerabilities
Microsoft SOA strategy: A failure to communicate?
SOA adoption marked by broad failure and wild success
SLA management latest entry in Tibco's SOA portfolio
SOA provides a test for QA, HP finds
OpenID: Leveraging a widely accepted identity Web service
IBM, Microsoft, Google join OpenID
SOA needs RIA – Burton Group
Boubez: SOA virtualization, SLAs and access control policy

Platforms and Servers
Tracking down managed memory leaks
Handling exceptions in .NET
.NET Compact Framework graphics
The Data Access Application Block
Decision time: .NET or J2EE?
A great .NET resource: .Net2TheMax
Delegates vs. interfaces in .NET
Project structure best practices
Working with PDFs in a .NET environment
Displaying errors with the error provider

Microsoft .NET Web services
Microsoft preps .NET 4.0 - framework improves on REST, MVC, JQuery support
How do I balance throughput requirements and interoperability?
APM software traces transactions across tiers, technologies
How you can learn M Grammar for Oslo modeling
Legacy modernization opens Windows for publisher
Former .NET Web developers ride Ruby and Rails application framework
Microsoft Oslo at PDC: Dial 'M' for modeling language
Yahoo proxy fight looms
New Microsoft site for architects
LAMP coders go hybrid route
Microsoft .NET Web services Research

RELATED GLOSSARY TERMS
Terms from Whatis.com − the technology online dictionary
Common Language Infrastructure  (SearchSOA.com)
Visual J#  (SearchSOA.com)

RELATED RESOURCES
2020software.com, trial software downloads for accounting software, ERP software, CRM software and business software systems
Search Bitpipe.com for the latest white papers and business webcasts
Whatis.com, the online computer dictionary

DISCLAIMER: Our Tips Exchange is a forum for you to share technical advice and expertise with your peers and to learn from other enterprise IT professionals. TechTarget provides the infrastructure to facilitate this sharing of information. However, we cannot guarantee the accuracy or validity of the material submitted. You agree that your use of the Ask The Expert services and your reliance on any questions, answers, information or other materials received through this Web site is at your own risk.



SOA Trends and Strategy - SOA Education, SOA Development, SOA Implementations
About Us  |  Contact Us  |  For Advertisers  |  For Business Partners  |  Site Index  |  RSS
SEARCH 
TechTarget provides technology professionals with the information they need to perform their jobs - from developing strategy, to making cost-effective purchase decisions and managing their organizations' technology projects - with its network of technology-specific websites, events and online magazines.

TechTarget Corporate Web Site  |  Media Kits  |  Site Map




All Rights Reserved, Copyright 2001 - 2009, TechTarget | Read our Privacy Policy
  TechTarget - The IT Media ROI Experts