Database
  Home arrow Database arrow Page 6 - Database Storage with the ASP.NET Web Matr...
ASP Free Forums 
.NET  
ASP  
ASP Code  
ASP.NET  
ASP.NET Code  
BrainDump  
C#  
Code Examples  
Database  
Database Code  
IIS  
Microsoft Access  
MS SQL Server  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
ASP Web Hosting  
ASP.NET Web Hosting 
Dedicated Servers 
Moblin 
JMSL Numerical Library 
Windows Web Hosting
 
IBM® developerWorks 
Sun Developer Network 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
DATABASE

Database Storage with the ASP.NET Web Matrix
By: Dan Wellman
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 10
    2005-09-14

    Table of Contents:
  • Database Storage with the ASP.NET Web Matrix
  • Create a database and table
  • Setting up a registration page
  • Coding the page
  • Error message
  • Password security

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Database Storage with the ASP.NET Web Matrix - Password security


    (Page 6 of 6 )

    A security measure often used when setting passwords is to enforce a minimum password length as the longer a password is, the longer it will take to crack it.  Minimum length password enforcing can easily be worked into the existing page with just one more label and an extension of the If control structure on the code page. 

    In design view, drag a label control next to the first password box, set the ID to lblPasswordLengthError, the fore color to red and the Text value to nothing.  Switch to the Code view and change the btnSubmit_Click sub as follows:

    Sub btnSubmit_Click(sender As Object, e As EventArgs)
        lblUsernameError.Text = ""
        lblPasswordError.Text = ""
        lblPasswordLengthError.Text = ""

        if txtPassword.Text.Length < 7 then
          lblPasswordLengthError.Text = "* Your password is not secure, please ensure
    it is 7 characters or more"
        Else If txtPassword.Text <> txtPassword2.Text Then
          lblPasswordError.Text = "* Verify password must match password"
        Else
          NewUser(txtUsername.Text, txtPassword.Text)
        End if
    End Sub    

    Now passwords will need to be seven characters or more before the database will accept them. 

    It would be nice if we lived in a world where clear-text passwords could be stored safely in a database.  Unfortunately however, we don’t.  Using a hashing algorithm to encrypt the password before storing it in the database table is a common method of secure password storage.  This is not unbeatable however, as a hacker may still be able to brute-force a hashed password if they can find this out by exploiting the database somehow.  This is much more time consuming and will be an effective deterrent. 

    A minor change must be made to the Code view.  You need to define a hashing method and write a method that will convert the contents of the password textbox into the hash before storing it.  Change the btnSubmit_Click sub to the following:

    Sub btnSubmit_Click(sender As Object, e As EventArgs)

        lblUsernameError.Text = ""
        lblPasswordError.Text = ""
        lblPasswordLengthError.Text = ""

        if txtPassword.Text.Length < 7 then
          lblPasswordLengthError.Text = "* Your password is not
    secure, please ensure it is 7 characters or more"
        else if txtPassword.Text <> txtPassword2.Text Then
          lblPasswordError.Text = "* Verify password must match
    password"
        Else
          Dim hashMethod as string
          hashMethod = "MD5"
          Dim encryptPassword as string
          encryptPassword = FormsAuthentication.HashPasswordForStoringInConfigFile
    (txtPassword.Text, hashMethod)
         

          NewUser(txtUsername.Text, encryptPassword)
        End if

    End Sub

     

    The finished Design view should now appear like this:

     

    Test the page and enter a username and password; now go to the Data Pane in the Web Matrix and view the table.  The entered password show now be encrypted.  If this failed, you may have forgotten to increase the maximum size of the Password column in the table.

    So there you go, using the Web Matrix as your IDE can result in clean code and increased productivity.  If you’re not using it already, maybe it’s something you should consider.


    DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.

       · Hi,This article explores the first of the built in Code Wizards that allow you...
     

    DATABASE ARTICLES

    - Database Programming in C# with MySQL : Usin...
    - Formatting Techniques for Data Access from E...
    - Data Access from Excel VBA
    - Generating a Multiple Table Crystal Report u...
    - ADO and the Command Object
    - On Wiring Up an ADO Data Control
    - Reading and Writing to Files on the Intranet
    - Using ADO Record to Create and Navigate Intr...
    - Using Data Access Pages to Access Data on a ...
    - Using ADO with the SQL Native Client
    - ADO`s Stream Object
    - Opening a Record Object Referencing an Open ...
    - Introducing Jasper (SQL Anywhere 10 Beta)
    - Creating a Database Project in VS 2005
    - Manipulating ADO Recordsets





    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway