Encrypting password Control VB.net

a5dzy2
a5dzy2 used Ask the Experts™
on
All,

I am working on creating a page that will allow techs to create a new user to log into our site.  The company is using a RAD called ironspeed to assist in creating their site.  I am looking for a way to encrypt the password that is entered in the textbox control and enter that encrypted hash into a database field.  

Now the encryption MD5 hasher is completed. I am using the function Microsoft provided and I do have this working on the sign-in page with passwords that have already been changed.  I am just not sure which control to use for this new operation.  Or which control to override with the MD5 hasher.  I am providing the code and am fairly new to VB.net programming.

Also I am not sure where to add the private MD5hasher function.

I am taking over this project and starting fix certain issues. I know there are other issues with formatting here but this is only the test site that they use so pardon the sloppiness.

Any assistance would be appreciated.



'''''''''''Here is the Hasher
 
Private Function GenerateHash(ByVal SourceText As String) As String
     ' Create a new instance of the MD5 object.
        Dim md5Hasher As MD5 = MD5.Create()
 
        ' Convert the input string to a byte array and compute the hash.
        Dim data As Byte() = md5Hasher.ComputeHash(Encoding.Default.GetBytes(SourceText))
 
        ' Create a new Stringbuilder to collect the bytes
        ' and create a string.
        Dim sBuilder As New StringBuilder()
 
        ' Loop through each byte of the hashed data 
        ' and format each one as a hexadecimal string.
        Dim i As Integer
        For i = 0 To data.Length - 1
            sBuilder.Append(data(i).ToString("x2"))
        Next i
 
        ' Return the hexadecimal string.
        Return sBuilder.ToString()
End Function
 
--------------------------------------------------------------------------------------------
''''''''''''''''''''''''Code for the page without hasher entered
 
 
' This file implements the TableControl, TableControlRow, and RecordControl classes for the 
' AddTechs.aspx page.  The Row or RecordControl classes are the 
' ideal place to add code customizations. For example, you can override the LoadData, 
' CreateWhereClause, DataBind, SaveData, GetUIData, and Validate methods.
 
#Region "Imports statements"
 
Option Strict On
Imports Microsoft.VisualBasic
Imports BaseClasses.Web.UI.WebControls
Imports System
Imports System.Collections
Imports System.Web
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports BaseClasses
Imports BaseClasses.Data
Imports BaseClasses.Utils
Imports ReportTools.ReportCreator
Imports ReportTools.Shared
Imports System.Security.Cryptography
Imports System.Text
 
  
        
Imports Testbed.Business
Imports Testbed.Data
#End Region
 
 
  
Namespace Testbed.UI.Controls.AddTechs
 
#Region "Section 1: Place your customizations here."
 
    
Public Class TechsRecordControl
        Inherits BaseTechsRecordControl
        ' The BaseTechsRecordControl implements the LoadData, DataBind and other
        ' methods to load and display the data in a table control.
 
        ' This is the ideal place to add your code customizations. For example, you can override the LoadData, 
        ' CreateWhereClause, DataBind, SaveData, GetUIData, and Validate methods.
    
		
End Class
 
#End Region
 
  
 
#Region "Section 2: Do not modify this section."
    
    
' Base class for the TechsRecordControl control on the AddTechs page.
' Do not modify this class. Instead override any method in TechsRecordControl.
Public Class BaseTechsRecordControl
        Inherits Testbed.UI.BaseApplicationRecordControl
 
        '  To customize, override this method in TechsRecordControl.
      Protected Overridable Sub Control_Init(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Init
 
      
      ' Setup the pagination events.
      
          
        ' Setup the filter and search events.
        
      
            ' Register the event handlers.
        
              AddHandler Me.role.SelectedIndexChanged, AddressOf role_SelectedIndexChanged
            
        End Sub
 
        '  To customize, override this method in TechsRecordControl.
        Protected Overridable Sub Control_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
        
    
    End Sub
 
        ' Read data from database.  To customize, override this method in TechsRecordControl.
        Public Overridable Sub LoadData()        
        
            If Not Me.RecordUniqueId Is Nothing AndAlso Me.RecordUniqueId.Trim <> "" Then
                Me.DataSource = TechsTable.GetRecord(Me.RecordUniqueId, True)
                Return
            End If
        
            Dim wc As WhereClause = Me.CreateWhereClause()
            
            If wc Is Nothing OrElse Not wc.RunQuery Then
                Me.DataSource = New TechsRecord()
                
                Return
            End If
            
 
          
              
            ' Retrieve the record from the database.
            
            Dim recList() As TechsRecord = TechsTable.GetRecords(wc, Nothing, 0, 2)
            If recList.Length = 0 Then
                
                wc.RunQuery = False
                                    
                
                Return
            End If
              
            Me.DataSource = CType(TechsRecord.Copy(recList(0), False), TechsRecord)
                  
        End Sub
 
        ' Populate the UI controls using the DataSource.  To customize, override this method in TechsRecordControl.
        Public Overrides Sub DataBind()
 
            MyBase.DataBind()
 
            ' Make sure that the DataSource is initialized.
            If Me.DataSource Is Nothing Then
                Return
            End If
        
      
            ' For each field, check to see if a value is specified.  If a value is specified,
            ' then format the value for display.  If no value is specified, use the default value (formatted).
 
        
            If Me.DataSource.emailSpecified Then
                Dim formattedValue As String = Me.DataSource.Format(TechsTable.email)
                Me.email.Text = formattedValue
              
            Else      
                Me.email.Text = TechsTable.email.Format(TechsTable.email.DefaultValue)
              
            End If
                    
            If Me.DataSource.passwordSpecified Then
                Dim formattedValue As String = Me.DataSource.Format(TechsTable.password)
                Me.password.Text = formattedValue
              
            Else      
                Me.password.Text = TechsTable.password.Format(TechsTable.password.DefaultValue)
              
            End If
                    
            If Me.DataSource.passwordMD5Specified Then
                Dim formattedValue As String = Me.DataSource.Format(TechsTable.passwordMD5)
                Me.passwordMD5.Text = formattedValue
              
            Else      
                Me.passwordMD5.Text = TechsTable.passwordMD5.Format(TechsTable.passwordMD5.DefaultValue)
              
            End If
                    
            If Me.DataSource.roleSpecified Then
                Me.PopulateroleDropDownList(Me.DataSource.role, 100)
            Else
                If Not Me.DataSource.IsCreated Then
                    Me.PopulateroleDropDownList(TechsTable.role.DefaultValue, 100)
                Else
                    Me.PopulateroleDropDownList(Nothing, 100)
                End If
            End If
                
            If Me.DataSource.TechSpecified Then
                Dim formattedValue As String = Me.DataSource.Format(TechsTable.Tech)
                Me.Tech.Text = formattedValue
              
            Else      
                Me.Tech.Text = TechsTable.Tech.Format(TechsTable.Tech.DefaultValue)
              
            End If
                    
            If Me.DataSource.UserName0Specified Then
                Dim formattedValue As String = Me.DataSource.Format(TechsTable.UserName0)
                Me.UserName1.Text = formattedValue
              
            Else      
                Me.UserName1.Text = TechsTable.UserName0.Format(TechsTable.UserName0.DefaultValue)
              
            End If
                    
            Me.IsNewRecord = True
            If Me.DataSource.IsCreated Then
                Me.IsNewRecord = False
        
                Me.RecordUniqueId = Me.DataSource.GetID.ToXmlString()
            End If
 
            
 
            ' Load data for each record and table UI control.
            ' Ordering is important because child controls get 
            ' their parent ids from their parent UI controls.
            Dim shouldResetControl as Boolean = False
            
      End Sub
 
        
        Public Overridable Sub ResetControl()
        
          
          End Sub
        
        
        ' To customize, override this method in TechsRecordControl.
        Public Overridable Sub SaveData()
 
            ' 1. Load the existing record from the database. Since we save the entire record, this ensures 
            ' that fields that are not displayed also properly initialized.
            Me.LoadData()
        
              
            ' 2. Validate the data.  Override in TechsRecordControl to add custom validation.
            Me.Validate()
 
            ' 3. Set the values in the record with data from UI controls.  Override in TechsRecordControl to set additional fields.
            Me.GetUIData()
 
            ' 4. Save in the database.
            ' We should not save the record if the data did not change. This
            ' will save a database hit and avoid triggering any database triggers.
            If Me.DataSource.IsAnyValueChanged Then
                ' Save record to database but do not commit.
                ' Auto generated ids are available after saving for use by child (dependent) records.
                Me.DataSource.Save()
              
            End If
            Me.DataChanged = True
            Me.ResetData = True
            ' Reseting of Me.IsNewRecord is moved to Save button's click even handler.
            ' Me.IsNewRecord() = False
            
        End Sub
 
        ' To customize, override this method in TechsRecordControl.
        Public Overridable Sub GetUIData()
            
            Dim clearDataSource As Boolean = False
            Dim col As BaseColumn
            For Each col In TechsRecord.TableUtils.TableDefinition.Columns()
                If col.ColumnType.Equals(BaseColumn.ColumnTypes.Unique_Identifier) Then
                    clearDataSource = True
                End If
            Next
 
            If clearDataSource Then
                Me.DataSource = New TechsRecord()
            End If
            
            Me.DataSource.Parse(Me.email.Text, TechsTable.email)
                          
            If  (Not Me.password.TextMode = TextBoxMode.Password) OrElse (Not Me.password.Text.Trim() = "") Then
                        
                Dim passwordformattedValue As String = Me.DataSource.Format(TechsTable.password)
                          
                If Me.password.Text.Trim() <> passwordformattedValue Then
                        
                    Me.DataSource.Parse(Me.password.Text, TechsTable.password)
                          
                End If
            End If
                      
            If  (Not Me.passwordMD5.TextMode = TextBoxMode.Password) OrElse (Not Me.passwordMD5.Text.Trim() = "") Then
                        
                Dim passwordMD5formattedValue As String = Me.DataSource.Format(TechsTable.passwordMD5)
                          
                If Me.passwordMD5.Text.Trim() <> passwordMD5formattedValue Then
                        
                    Me.DataSource.Parse(Me.passwordMD5.Text, TechsTable.passwordMD5)
                          
                End If
            End If
                      
            Me.DataSource.Parse(GetValueSelectedPageRequest(Me.role), TechsTable.role)
                  
            Me.DataSource.Parse(Me.Tech.Text, TechsTable.Tech)
                          
            Me.DataSource.Parse(Me.UserName1.Text, TechsTable.UserName0)
                          
        End Sub
 
        
      
        ' To customize, override this method in TechsRecordControl.
        Public Overridable Function CreateWhereClause() As WhereClause
        
            Dim wc As WhereClause
            TechsTable.Instance.InnerFilter = Nothing
            wc = New WhereClause()
            ' Compose the WHERE clause consiting of:
            ' 1. Static clause defined at design time.
            ' 2. User selected filter criteria.
            ' 3. User selected search criteria.
            
            ' Retrieve the record id from the URL parameter.
            Dim recId As String = Me.Page.Request.QueryString.Item("Techs")
            If recId Is Nothing OrElse recId.Trim = "" Then
            ' Get the error message from the application resource file.
            Return Nothing
            End If
              
            HttpContext.Current.Session("QueryString in AddTechs") = recId
                
            If KeyValue.IsXmlKey(recId) Then
            Dim pkValue As KeyValue = KeyValue.XmlToKey(recId)
                    
                wc.iAND(TechsTable.Tech, BaseFilter.ComparisonOperator.EqualsTo, pkValue.GetColumnValue(TechsTable.Tech).ToString())
            Else
                    
                wc.iAND(TechsTable.Tech, BaseFilter.ComparisonOperator.EqualsTo, recId)
            End If
                
            Return wc
          
        End Function
        
        ' This CreateWhereClause is used for loading list of suggestions for Auto Type-Ahead feature.
        Public Overridable Function CreateWhereClause(ByVal searchText as String, ByVal fromSearchControl as String, ByVal AutoTypeAheadSearch as String, ByVal AutoTypeAheadWordSeparators as String) As WhereClause
            TechsTable.Instance.InnerFilter = Nothing
            Dim wc As WhereClause = New WhereClause()
            ' Compose the WHERE clause consiting of:
            ' 1. Static clause defined at design time.
            ' 2. User selected filter criteria.
            ' 3. User selected search criteria.
            Dim appRelativeVirtualPath As String = CType(HttpContext.Current.Session("AppRelativeVirtualPath"), String)
            
            
            ' Adds clauses if values are selected in Filter controls which are configured in the page.
          
       
          
            Return wc
        End Function
          
          
        'Formats the resultItem and adds it to the list of suggestions.
        Public Overridable Function FormatSuggestions(ByVal prefixText As String, ByVal resultItem as String, _
                                                 ByVal columnLength As Integer, ByVal AutoTypeAheadDisplayFoundText as String, _
                                                 ByVal autoTypeAheadSearch as String, ByVal AutoTypeAheadWordSeparators as String, _
                                                 ByVal resultList as ArrayList) as Boolean
            Dim index As Integer = resultItem.ToUpper(System.Threading.Thread.CurrentThread.CurrentCulture).IndexOf(prefixText.ToUpper(System.Threading.Thread.CurrentThread.CurrentCulture))
            Dim itemToAdd As String = ""
            Dim isFound as Boolean = False
            Dim isAdded as Boolean = False
            ' Get the index where prfixt is at the beginning of resultItem. If not found then, index of word which begins with prefixText.
            If InvariantLCase(autoTypeAheadSearch).equals("wordsstartingwithsearchstring") and not index = 0 Then
                ' Expression to find word which contains AutoTypeAheadWordSeparators followed by prefixText
                Dim regex1 As System.Text.RegularExpressions.Regex = new System.Text.RegularExpressions.Regex( AutoTypeAheadWordSeparators + prefixText, System.Text.RegularExpressions.RegexOptions.IgnoreCase)
                If regex1.IsMatch(resultItem) Then
                    index = regex1.Match(resultItem).Index
                    isFound = True
                End If
                ' If the prefixText is found immediatly after white space then starting of the word is found so don not search any further
                If not resultItem(index).ToString() = " " Then
                    ' Expression to find beginning of the word which contains AutoTypeAheadWordSeparators followed by prefixText
                    Dim regex As System.Text.RegularExpressions.Regex = new System.Text.RegularExpressions.Regex("\\S*" + AutoTypeAheadWordSeparators + prefixText, System.Text.RegularExpressions.RegexOptions.IgnoreCase)
                    If regex.IsMatch(resultItem) Then
                        index = regex.Match(resultItem).Index
                        isFound = True
                    End If
                 End If
            End If
            ' If autoTypeAheadSearch value is wordsstartingwithsearchstring then, extract the substring only if the prefixText is found at the 
            ' beginning of the resultItem (index = 0) or a word in resultItem is found starts with prefixText. 
            If index = 0 Or isFound Or InvariantLCase(autoTypeAheadSearch).Equals("anywhereinstring") then
                If InvariantLCase(AutoTypeAheadDisplayFoundText).equals("atbeginningofmatchedstring") Then
                    ' Expression to find beginning of the word which contains prefixText
                    Dim regex1 As System.Text.RegularExpressions.Regex = new System.Text.RegularExpressions.Regex("\\S*" + prefixText, System.Text.RegularExpressions.RegexOptions.IgnoreCase)
                    '  Find the beginning of the word which contains prefexText
                    If (StringUtils.InvariantLCase(autoTypeAheadSearch).Equals("anywhereinstring") AndAlso regex1.IsMatch(resultItem)) Then
                        index = regex1.Match(resultItem).Index
                        isFound = True
                    End If
                    ' Display string from the index till end of the string if sub string from index till end is less than columnLength value.
                    If Len(resultItem) - index <= columnLength Then
                        If index = 0 Then 
                            itemToAdd = resultItem 
                        Else
                            itemToAdd = "..." & resultItem.Substring(index, Len(resultItem) - index) 
                        End If
                    Else
                        If index = 0 Then
                            itemToAdd = resultItem.Substring(index, (columnLength - 3)) & "..."
                        Else
                            'Truncate the string to show only columnLength - 6 characters as begining and trailing "..." has to be appended.
                            itemToAdd = "..." & resultItem.Substring(index , columnLength - 6) & "..." 
                        End If
                    End If
                ElseIf InvariantLCase(AutoTypeAheadDisplayFoundText).equals("inmiddleofmatchedstring") Then
                    Dim subStringBeginIndex as Integer = CType(columnLength/2, Integer)
                    If Len(resultItem) <= columnLength Then
                        itemToAdd = resultItem
                    Else
                        ' Sanity check at end of the string
                        If index + Len(prefixText) = columnLength Then
                            itemToAdd =  "..." & resultItem.Substring(index-columnLength,index)
                        ElseIf Len(resultITem) - index < subStringBeginIndex Then 
                            ' Display string from the end till columnLength value if, index is closer to the end of the string.
                            itemToAdd =  "..." & resultItem.Substring(Len(resultItem)-columnLength,Len(resultItem))
                        ElseIf index <= subStringBeginIndex Then 
                            ' Sanity chet at beginning of the string
                            itemToAdd =  resultItem.Substring(0, columnLength) & "..."
                        Else
                            ' Display string containing text before the prefixText occures and text after the prefixText
                            itemToAdd =  "..." & resultItem.Substring(index - subStringBeginIndex, columnLength) & "..." 
                        End If
                    End If
                ElseIf InvariantLCase(AutoTypeAheadDisplayFoundText).equals("atendofmatchedstring") Then
                     ' Expression to find ending of the word which contains prefexText
                    Dim regex1 as System.Text.RegularExpressions.Regex = new System.Text.RegularExpressions.Regex("\s", System.Text.RegularExpressions.RegexOptions.IgnoreCase)
                    ' Find the ending of the word which contains prefexText
                    If regex1.IsMatch(resultItem, index + 1) Then
                        index = regex1.Match(resultItem, index + 1).Index
                    Else
                        ' If the word which contains prefexText is the last word in string, regex1.IsMatch returns false.
                        index = resultItem.Length
                    End If
                    If index > Len(resultItem) Then
                        index = Len(resultItem)
                    End If
                    ' If text from beginning of the string till index is less than columnLength value then, display string from the beginning till index.
                    If  index <= columnLength Then
                        if index = Len(resultItem) then   'Make decision to append "..."
                            itemToAdd = resultItem.Substring(0,index)
                        Else
                            itemToAdd = resultItem.Substring(0,index) & "..."
                        End If
                    Else
                        If index = Len(resultItem) Then
                            itemToAdd = "..." & resultItem.Substring(index - (columnLength - 3), (columnLength - 3))
                        Else
                            'Truncate the string to show only columnLength - 6 characters as begining and trailing "..." has to be appended.
                            itemToAdd = "..." & resultItem.Substring(index - (columnLength - 6), columnLength - 6) & "..." 
                        End If
                    End If
                End If
                
                ' Remove newline character from itemToAdd
                Dim prefixTextIndex As Integer = itemToAdd.IndexOf(prefixText, StringComparison.CurrentCultureIgnoreCase)
                ' If itemToAdd contains any newline after the search text then show text only till newline
                Dim regex2 As System.Text.RegularExpressions.Regex = New System.Text.RegularExpressions.Regex("(" & vbCrLf & "|" & vbLf & ")", System.Text.RegularExpressions.RegexOptions.IgnoreCase)
                Dim newLineIndexAfterPrefix As Integer = -1
                If regex2.IsMatch(itemToAdd, prefixTextIndex) Then
                    newLineIndexAfterPrefix = regex2.Match(itemToAdd, prefixTextIndex).Index
                End If
                If (newLineIndexAfterPrefix > -1) Then
                    If itemToAdd.EndsWith("...") Then
                        itemToAdd = (itemToAdd.Substring(0, newLineIndexAfterPrefix) + "...")
                    Else
                        itemToAdd = itemToAdd.Substring(0, newLineIndexAfterPrefix)
                    End If
                End If
                ' If itemToAdd contains any newline before search text then show text which comes after newline
                Dim regex3 As System.Text.RegularExpressions.Regex = New System.Text.RegularExpressions.Regex("(" & vbCrLf & "|" & vbLf & ")", (System.Text.RegularExpressions.RegexOptions.IgnoreCase Or System.Text.RegularExpressions.RegexOptions.RightToLeft))
                Dim newLineIndexBeforePrefix As Integer = -1
                If regex3.IsMatch(itemToAdd, prefixTextIndex) Then
                    newLineIndexBeforePrefix = regex3.Match(itemToAdd, prefixTextIndex).Index
                End If
                If (newLineIndexBeforePrefix > -1) Then
                    If itemToAdd.StartsWith("...") Then
                        itemToAdd = ("..." + itemToAdd.Substring((newLineIndexBeforePrefix + regex3.Match(itemToAdd, prefixTextIndex).Length)))
                    Else
                        itemToAdd = itemToAdd.Substring((newLineIndexBeforePrefix + regex3.Match(itemToAdd, prefixTextIndex).Length))
                    End If
                End If
 
                If Not itemToAdd is nothing AndAlso Not resultList.Contains(itemToAdd) Then
                    resultList.Add(itemToAdd)
                    isAdded = true
                End If
            End If
            Return isAdded
        End Function
        
 
        ' To customize, override this method in TechsRecordControl.
        Public Overridable Sub Validate() 
            ' Initially empty.  Override to add custom validation.
        End Sub
 
        Public Overridable Sub Delete()
        
            If Me.IsNewRecord() Then
                Return
            End If
 
            Dim pk As KeyValue = KeyValue.XmlToKey(Me.RecordUniqueId)
            TechsTable.DeleteRecord(pk)
 
          
        End Sub
 
        Private Sub Control_PreRender(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.PreRender
            Try
                DbUtils.StartTransaction()
 
                If Not Me.Page.ErrorOnPage AndAlso (Me.Page.IsPageRefresh OrElse Me.DataChanged OrElse Me.ResetData) Then
                    Me.LoadData()
                    Me.DataBind()
                End If
 
            Catch ex As Exception
                Utils.MiscUtils.RegisterJScriptAlert(Me, "BUTTON_CLICK_MESSAGE", ex.Message)
            Finally
                DbUtils.EndTransaction()
            End Try
        End Sub
        
        
 
        Protected Overrides Sub LoadViewState(ByVal savedState As Object)
            MyBase.LoadViewState(savedState)
            Dim isNewRecord As String = CType(ViewState("IsNewRecord"), String)
            If Not isNewRecord Is Nothing AndAlso isNewRecord.Trim <> "" Then
                Me.IsNewRecord = Boolean.Parse(isNewRecord)
            End If
            
            Dim myCheckSum As String = CType(ViewState("CheckSum"), String)
            If Not myCheckSum Is Nothing AndAlso myCheckSum.Trim <> "" Then
                Me.CheckSum = myCheckSum
            End If
            
        End Sub
 
        Protected Overrides Function SaveViewState() As Object
            ViewState("IsNewRecord") = Me.IsNewRecord.ToString()
            ViewState("CheckSum") = Me.CheckSum
            
            Return MyBase.SaveViewState()
        End Function
        
        
        ' Generate the event handling functions for pagination events.
            
      
        ' Generate the event handling functions for filter and search events.
            
        Public Overridable Function CreateWhereClause_roleDropDownList() As WhereClause
            Return New WhereClause()
        End Function
                
        ' Fill the role list.
        Protected Overridable Sub PopulateroleDropDownList( _
                ByVal selectedValue As String, _
                ByVal maxItems As Integer)
                  
            Me.role.Items.Clear()
                      
            Me.role.Items.Add(New ListItem("administrator", "administrator"))
            Me.role.Items.Add(New ListItem("core", "core"))
            Me.role.Items.Add(New ListItem("mamagement", "mamagement"))
            Me.role.Items.Add(New ListItem("operator", "operator"))
            Me.role.Items.Add(New ListItem("uppermanagement", "uppermanagement"))
            ' Setup the selected item.
            If Not selectedValue Is Nothing AndAlso _
                selectedValue.Trim <> "" AndAlso _
                Not SetSelectedValue(Me.role, selectedValue) AndAlso _
                Not MiscUtils.SetSelectedValue(Me.role, TechsTable.role.Format(selectedValue))Then
                Dim fvalue As String = TechsTable.role.Format(selectedValue)
                Dim item As ListItem = New ListItem(fvalue, selectedValue)
                item.Selected = True
                Me.role.Items.Insert(0, item)
            End If
 
                  
            Me.role.Items.Insert(0, New ListItem(Page.GetResourceValue("Txt:PleaseSelect", "Testbed"), "--PLEASE_SELECT--"))
                  
        End Sub
                
              Protected Overridable Sub role_SelectedIndexChanged(ByVal sender As Object, ByVal args As EventArgs)
              Dim selectedValue As String = MiscUtils.GetValueSelectedPageRequest(Me.role)
              If Not selectedValue Is Nothing AndAlso _
              selectedValue.Trim <> "" AndAlso _
              Not SetSelectedValue(Me.role, selectedValue) AndAlso _
              Not MiscUtils.SetSelectedValue(Me.role, TechsTable.role.Format(selectedValue)) Then
              Dim fvalue As String = TechsTable.role.Format(selectedValue)
              Dim item As ListItem = New ListItem(fvalue, selectedValue)
              item.Selected = True
              Me.role.Items.Insert(0, item)
              End If
              End Sub
            
   
        Private _IsNewRecord As Boolean = True
        Public Overridable Property IsNewRecord() As Boolean
            Get
                Return Me._IsNewRecord
            End Get
            Set(ByVal value As Boolean)
                Me._IsNewRecord = value
            End Set
        End Property
 
        Private _DataChanged As Boolean = False
        Public Overridable Property DataChanged() As Boolean
            Get
                Return Me._DataChanged
            End Get
            Set(ByVal Value As Boolean)
                Me._DataChanged = Value
            End Set
        End Property
 
        Private _ResetData As Boolean = False
        Public Overridable Property ResetData() As Boolean
            Get
                Return Me._ResetData
            End Get
            Set(ByVal Value As Boolean)
                Me._ResetData = Value
            End Set
        End Property
        
        Public Property RecordUniqueId() As String
            Get
                Return CType(Me.ViewState("BaseTechsRecordControl_Rec"), String)
            End Get
            Set(ByVal value As String)
                Me.ViewState("BaseTechsRecordControl_Rec") = value
            End Set
        End Property
        
        Private _DataSource As TechsRecord
        Public Property DataSource() As TechsRecord
            Get
                Return Me._DataSource
            End Get
            Set(ByVal value As TechsRecord)
                Me._DataSource = value
            End Set
        End Property
 
        Private _checkSum As String
        Public Overridable Property CheckSum() As String
            Get
                Return Me._checkSum
            End Get
            Set(ByVal value As String)
                Me._checkSum = value
            End Set
        End Property
        
        Private _TotalPages As Integer
        Public Property TotalPages() As Integer
            Get
                Return Me._TotalPages
            End Get
            Set(ByVal value As Integer)
                Me._TotalPages = value
            End Set
        End Property
        
        Private _PageIndex As Integer
        Public Property PageIndex() As Integer
            Get
                ' Return the PageIndex
                Return Me._PageIndex
            End Get
            Set(ByVal value As Integer)
                Me._PageIndex = value
            End Set
        End Property
    
        Private _PageSize As Integer
        Public Property PageSize() As Integer
            Get
                Return Me._PageSize
            End Get
            Set(ByVal value As Integer)
                Me._PageSize = value
            End Set
        End Property
    
        Private _TotalRecords As Integer
        Public Property TotalRecords() As Integer
            Get
                Return Me._TotalRecords
            End Get
            Set(ByVal value As Integer)
                If Me.PageSize > 0 Then
                    Me.TotalPages = CInt(Math.Ceiling(value / Me.PageSize))
                End If
 
                Me._TotalRecords = value
            End Set
        End Property
        
        Private _DisplayLastPage As Boolean
        Public Property DisplayLastPage() As Boolean
            Get
                Return Me._DisplayLastPage
            End Get
            Set(ByVal value As Boolean)
                Me._DisplayLastPage = value
            End Set
        End Property
        
        
 
#Region "Helper Properties"
        
        Public ReadOnly Property email() As System.Web.UI.WebControls.TextBox
            Get
                Return CType(BaseClasses.Utils.MiscUtils.FindControlRecursively(Me, "email"), System.Web.UI.WebControls.TextBox)
            End Get
        End Property
            
        Public ReadOnly Property emailLabel() As System.Web.UI.WebControls.Literal
            Get
                Return CType(BaseClasses.Utils.MiscUtils.FindControlRecursively(Me, "emailLabel"), System.Web.UI.WebControls.Literal)
            End Get
        End Property
        
        Public ReadOnly Property password() As System.Web.UI.WebControls.TextBox
            Get
                Return CType(BaseClasses.Utils.MiscUtils.FindControlRecursively(Me, "password"), System.Web.UI.WebControls.TextBox)
            End Get
        End Property
            
        Public ReadOnly Property passwordLabel() As System.Web.UI.WebControls.Literal
            Get
                Return CType(BaseClasses.Utils.MiscUtils.FindControlRecursively(Me, "passwordLabel"), System.Web.UI.WebControls.Literal)
            End Get
        End Property
        
        Public ReadOnly Property passwordMD5() As System.Web.UI.WebControls.TextBox
            Get
                Return CType(BaseClasses.Utils.MiscUtils.FindControlRecursively(Me, "passwordMD5"), System.Web.UI.WebControls.TextBox)
            End Get
        End Property
            
        Public ReadOnly Property passwordMD5Label() As System.Web.UI.WebControls.Literal
            Get
                Return CType(BaseClasses.Utils.MiscUtils.FindControlRecursively(Me, "passwordMD5Label"), System.Web.UI.WebControls.Literal)
            End Get
        End Property
        
        Public ReadOnly Property role() As System.Web.UI.WebControls.DropDownList
            Get
                Return CType(BaseClasses.Utils.MiscUtils.FindControlRecursively(Me, "role"), System.Web.UI.WebControls.DropDownList)
            End Get
        End Property
            
        Public ReadOnly Property roleLabel() As System.Web.UI.WebControls.Literal
            Get
                Return CType(BaseClasses.Utils.MiscUtils.FindControlRecursively(Me, "roleLabel"), System.Web.UI.WebControls.Literal)
            End Get
        End Property
        
        Public ReadOnly Property Tech() As System.Web.UI.WebControls.TextBox
            Get
                Return CType(BaseClasses.Utils.MiscUtils.FindControlRecursively(Me, "Tech"), System.Web.UI.WebControls.TextBox)
            End Get
        End Property
            
        Public ReadOnly Property TechLabel() As System.Web.UI.WebControls.Literal
            Get
                Return CType(BaseClasses.Utils.MiscUtils.FindControlRecursively(Me, "TechLabel"), System.Web.UI.WebControls.Literal)
            End Get
        End Property
        
        Public ReadOnly Property TechsTitle() As System.Web.UI.WebControls.Literal
            Get
                Return CType(BaseClasses.Utils.MiscUtils.FindControlRecursively(Me, "TechsTitle"), System.Web.UI.WebControls.Literal)
            End Get
        End Property
        
        Public ReadOnly Property UserName1() As System.Web.UI.WebControls.TextBox
            Get
                Return CType(BaseClasses.Utils.MiscUtils.FindControlRecursively(Me, "UserName1"), System.Web.UI.WebControls.TextBox)
            End Get
        End Property
            
        Public ReadOnly Property usernameLabel() As System.Web.UI.WebControls.Literal
            Get
                Return CType(BaseClasses.Utils.MiscUtils.FindControlRecursively(Me, "usernameLabel"), System.Web.UI.WebControls.Literal)
            End Get
        End Property
        
    #End Region
 
    #Region "Helper Functions"
 
    Public Overrides Overloads Function ModifyRedirectUrl(ByVal url As String, ByVal arg As String, ByVal bEncrypt As Boolean) As String
        Return Me.Page.EvaluateExpressions(url, arg, bEncrypt, Me)
    End Function
 
    Public Overrides Overloads Function EvaluateExpressions(ByVal url As String, ByVal arg As String, ByVal bEncrypt As Boolean) As String
    Dim rec As TechsRecord = Nothing
            
            Try
                rec = Me.GetRecord()
            Catch ex As Exception
                ' Do nothing
            End Try
 
            If rec Is Nothing AndAlso url.IndexOf("{") >= 0 Then
                ' Localization.
                
            Throw New Exception(Page.GetResourceValue("Err:RecDataSrcNotInitialized", "Testbed"))
                    
            End If
            Return EvaluateExpressions(url, arg, rec, bEncrypt)
        End Function
 
        Public Overridable Function GetRecord() As TechsRecord
            If Not Me.DataSource Is Nothing Then
              Return Me.DataSource
            End If
            
            Return New TechsRecord()
          
        End Function
 
        Public Shadows ReadOnly Property Page() As BaseApplicationPage
            Get
                Return DirectCast(MyBase.Page, BaseApplicationPage)
            End Get
        End Property
 
#End Region
 
End Class
 
  
 
#End Region
    
  
End Namespace

Open in new window

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®

Commented:
You might want to add a module to your region, and drop it in there so it's readily available...

So after End Class and before End Namespace, you could create:


...
#End Region
 
End Class
 
  
 
#End Region
    
Module Hasher
   ' CODE GOES HERE
   Private Function GenerateHash(ByVal SourceText As String) As String
     ' Create a new instance of the MD5 object.
        Dim md5Hasher As MD5 = MD5.Create()
 
        ' Convert the input string to a byte array and compute the hash.
        Dim data As Byte() = md5Hasher.ComputeHash(Encoding.Default.GetBytes(SourceText))
 
        ' Create a new Stringbuilder to collect the bytes
        ' and create a string.
        Dim sBuilder As New StringBuilder()
 
        ' Loop through each byte of the hashed data 
        ' and format each one as a hexadecimal string.
        Dim i As Integer
        For i = 0 To data.Length - 1
            sBuilder.Append(data(i).ToString("x2"))
        Next i
 
        ' Return the hexadecimal string.
        Return sBuilder.ToString()
   End Function
 
End Module
  
End Namespace

Open in new window

Author

Commented:
Thanks Jake072,

Now to have the data that is entrered into the passwordMD5 field would I do this in the savedata() sub, databind() sub, or GetUIdata() sub?
 I believe I would have to call the hash with the savedata() is that correct?  I just want to hash whatever password is entered and store it in our database.  That should complete this part.  
I will basically be overriding the Subs in region 2 and adding code to region 1 to preform this.  This will be because anything added in region 2 will be overwritten when the RAD re-builds the app.  

Commented:
a5dzy2,

I'm just off for some work this afternoon, I'll look at your code this evening, in about 3-4 hours.

Cheers,

Jake
Success in ‘20 With a Profitable Pricing Strategy

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden using our free interactive tool and use it to determine the right price for your IT services. Start calculating Now!

Author

Commented:
Thanks Jake,

I will wait for your reply.
Commented:
a5dzy2,

So sorry about the delay, I've been quite busy this weekend =)

To encrypt the stored password, you would use it in savedata(). but also "un" hash it in the databind(), otherwise you'll set the textfield to the hashed value, and if they resave it, it'll then be a hash of a hash, and you won't get the correct data.

Jake

Author

Commented:
No worries I had been busy this weekend also was just checking.  Everything works well however I had to hash the data in the getUIdata function.   Guessing it is part of the way the RAD writes the application.   Thank you very much for your help.

Author

Commented:
He was very good understood my problem with my limited understanding of the subject and not being able to fully explain the issue.

Commented:
a5dzy2,

Doh!  Yes, I responded to quickly, you are obviously right, sorry about that, but indeed, getUIdata is the one =)

Jake

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial