ASP.NET
  Home arrow ASP.NET arrow Page 3 - 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 
Mobile Linux 
App Generation ROI 
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? 
ASP.NET

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

    Table of Contents:
  • Database Storage with the ASP.NET Web Matrix: Update Page
  • Important Details and Updates
  • Calling the Function
  • Taking Care of 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: Update Page - Calling the Function


    (Page 3 of 4 )

    You now need a sub to call the function, so switch back to Design view and double-click the Update button element.  We will use the same code to blank any message text at the beginning of the sub to reset any error messages that the user may have already received when viewing the page. Add the following code to the sub:

    lblUsernameError.Text = ""
    lblPasswordLengthError.Text = ""
    lblNewPasswordError.Text = ""

    If you remember the Registration page we created a couple of examples ago, you’ll know that the password a user chooses is written to the database table in an MD5 encrypted format, so we will also need to build that capability into this page.  The code in this is exactly the same as it was in the Registration page:

    Dim hashMethod as string
        hashMethod = "MD5"
        Dim encryptPassword as string
        encryptPassword = FormsAuthentication.HashPasswordForStoringInConfigFile
    (txtNewPassword.Text, hashMethod)

    All we need now is an If statement to either display an error message, or execute the data operation if the username exists and the new password meets the predefined criteria.  These criteria are essentially the same as the ones in the Registration page; namely that the two password fields must match, and that the new password should be more than seven characters long:

    If txtNewPassword.Text.Length < 7 then
          lblPasswordLengthError.Text = "* Your password is not
    secure, please ensure it is 7 characters or more"
    Else if txtNewPassword.Text <> txtVerifyNewPassword.Text Then
          lblNewPasswordError.Text = "* Verify password must match
    password"
    Else if updateUserPass(txtUsername.Text, encryptPassword) = 0
    Then
          lblUsernameError.Text = "* Your username does not appear to
    exist"
    Else
          updateUserPass(txtUsername.Text, encryptPassword)
    End If

    That is all we need.  Save the file in the private folder of the site’s directory structure; as with the previous example page, we will insist that only authenticated visitors can access the page.  To test the page properly, you may find it useful to register two different usernames with the same password so that they show up in your database table with the same MD5 hash.  This way, you will know for sure when you update the password of one of the usernames, because it will no longer exactly match the hash of the other username.

    More ASP.NET Articles
    More By Dan Wellman


       · Hi all,Welcome to the fourth and penultimate article in the Web Matrix series. ...
     

    ASP.NET ARTICLES

    - Developing a Mini ASP.NET AJAX Server Centri...
    - Disadvantages of the ASP.NET MVC Framework
    - Advantages of the ASP.NET MVC Approach
    - ASP.NET Web Forms Weaknesses
    - ASP.NET Web Forms Meets ASP.NET MVC
    - Source Code for Saving and Retrieving Data w...
    - Using GridView to Save and Retrieve Data wit...
    - Handling Dynamic Images in ASP.NET 3.5 AJAX ...
    - Retrieving Data with AJAX and the GridView C...
    - Playing with Images in ASP.NET 3.5 AJAX Appl...
    - Saving and Retrieving Data with AJAX
    - Enhancing PHP Via the ASP.NET AJAX Framework...
    - Enhancing PHP Programming with the ASP.NET A...
    - Classes and ASP.NET AJAX
    - Using ASP.NET AJAX

     
    Best Practices for Windows Vista Migration Presentation
    Dell and Microsoft recently held a series of face-to-face seminars entitled, &qu....

     
    Creating a Culture for Code Reuse
    If you oversee development teams you know that like it or not proprietary and ex....

     
    Keys to Web Application Acceleration: Advances in Delivery Systems
    Accelerate Web apps by up to 5x. Ensure significantly faster access to the Web a....

     
    Optimizing Application Monitoring
    Tired of finding out from your customers that you're offline? This white paper e....

     
    Solaris to Solaris Migration -- Migrating applications from Sun SPARC to Dell PowerEdge R900
    This comprehensive Migration Guide reviews the approach that Principled Technolo....

     




    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway
    Stay green...Green IT