This message was edited by simmonsl at 2006-12-21 14:53:18
:
This message was edited by DrMarten at 2006-12-21 8:10:25
: Hi,
:
: 2nd line in DataManager.Vb in function CheckUserPassword
: has
AgencyUser as an undefined type. The line is>>
: Dim objReturn As AgencyUser
:
:
: Private Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load, Me.Load
: 'Dim aAgencyList As New ArrayList
:
: If Request.QueryString("LO") = "True" Then
: Session.Clear()
: End If
:
:
: objData = New DataManager(ConfigurationManager.AppSettings("DatabaseServer"), _
: ConfigurationManager.AppSettings("DatabaseCatalog"), ConfigurationManager.AppSettings("DatabaseUsername"), _
: ConfigurationManager.AppSettings("DatabasePassword"))
:
: ' I've added the following to populate your listbox
: ' from your FetchActiveAgencies function.
: Dim index As Integer
: Dim myControl As ListBox
: myControl = Me.FindControl("lstAgency")
: myControl.SelectionMode = ListSelectionMode.Single
: 'This loop may need to start with a 1.
: ' I can't remember whether 1st item is 0 or a 1 with a ListBox.
: For index = 0 To objData.objReturnData.Count
: myControl.SelectedIndex = index
: myControl.SelectedValue = objData.objReturnData(index)
:
: ' aAgencyList(index, index) = objData.FetchActiveAgencies
: 'lstAgency.Item(index) = aAgencyList(index, index)
: Next
:
:
: 'Login1.Controls.Item(0).datasource = aAgencyList
: 'Login1.Controls.Item(0).TemplateSourceDirectory(aAgencyList)
: 'Login1.Controls.Item(0) = aAgencyList
:
: Login1.Controls.Item(0).DataBind()
:
:
: End Sub
:
:
: To achieve the above the DataManager Class now looks like.>>
: The added lines are highlighted as.>>
:
'The following line was added.
: The reason being is i wanted to make the arraylist "PUBLIC" so it can be seen by the Login.aspx.vb code as arraylist
objReturnData
:
:
: Imports Microsoft.VisualBasic
: Imports System.Data
: Imports System.Data.SqlClient
: Imports System.Security.Cryptography
: Imports System.Text
: Imports System.Data.SqlTypes
: Imports System.Configuration.ConfigurationManager
: Imports System
:
:
: Public Class DataManager
:
: #Region " PUBLIC PROPERTIES AND METHODS "
: Public ReadOnly Property ConnectionString() As String
: Get
: ConnectionString = _ConnectionString
: End Get
: End Property
: #End Region
:
:
: #Region " PRIVATE PROPERTIES AND METHODS "
: Private conSQL As SqlConnection
: Private cmdSQL As SqlCommand
: Private _ConnectionString As String
: 'The following line was added.
: Public objReturnData As ArrayList
:
:
: Private Function FormatSingleQuotes(ByVal inString As String) As String
: Try
: Dim strReturn As String
: Dim intLastLocation As Integer
:
: strReturn = inString
: intLastLocation = 0
: Do While InStr(intLastLocation + 1, strReturn, "'") > 0 And Mid(strReturn, InStr(intLastLocation + 1, strReturn, "'") + 1, 1) <> "'"
: strReturn = Left(strReturn, InStr(intLastLocation + 1, strReturn, "'")) & "'" & Mid(strReturn, InStr(intLastLocation + 1, strReturn, "'") + 1)
: intLastLocation = InStr(intLastLocation + 1, strReturn, "'") + 1
: Loop
:
: Return strReturn
: Catch ex As Exception
: Return inString
: End Try
:
: End Function
:
: Function ToHexString(ByVal bytes() As Byte) As String
: Dim hexDigits As Char() = {"0"c, "1"c, "2"c, "3"c, "4"c, _
: "5"c, "6"c, "7"c, "8"c, "9"c, _
: "A"c, "B"c, "C"c, "D"c, "E"c, "F"c}
: Dim chars(bytes.Length * 2) As Char
: Dim i As Integer
:
: For i = 0 To bytes.Length - 1
: Dim b As Integer = bytes(i)
: chars((i * 2)) = hexDigits(b >> 4)
: chars((i * 2) + 1) = hexDigits(b And &HF)
: Next i
: Return New String(chars)
: End Function
:
:
: #End Region
:
:
: Public Function FetchActiveAgencies() As ArrayList
: Dim dsData As SqlDataReader
: Dim objReturn As New ArrayList
:
: Dim AgencyID As String
: Dim Name As String
:
: 'cmdSQL.CommandText = "SELECT AgencyID, AgencyName FROM BMS.dbo.Agency WHERE Active = 1 ORDER BY AgencyName"
: 'dsData = cmdSQL.ExecuteReader
: 'Do While dsData.Read = True
: ' objReturn.Add(New Agency(Val(dsData.GetValue(0).ToString), dsData.GetValue(1).ToString))
: 'Loop
:
:
: Dim Agency As New Agency(1, "Item One")
: Name = Agency.GetName(Name)
: objReturn.Add(New Agency((Agency.GetAgencyID(AgencyID)), (Agency.GetName(Name))))
: Agency.AddAgency(2, "Item Two")
: Name = Agency.GetName(Name)
: objReturn.Add(New Agency((Agency.GetAgencyID(AgencyID)), (Agency.GetName(Name))))
: Agency.AddAgency(3, "Item Three")
: Name = Agency.GetName(Name)
: objReturn.Add(New Agency((Agency.GetAgencyID(AgencyID)), (Agency.GetName(Name))))
: Agency.AddAgency(4, "Item Four")
: Name = Agency.GetName(Name)
: objReturn.Add(New Agency((Agency.GetAgencyID(AgencyID)), (Agency.GetName(Name))))
:
:
: ' dsData.Close()
: dsData = Nothing
: 'The following line was added.
: objReturnData = objReturn
: Return objReturn
: End Function
:
:
: ' PASSWORD CHECKERS
: Public Function CheckInitPassword(ByVal UserLogin As String, ByVal Password As String) As Integer
: Dim initReturn As Boolean
: Dim hashedBytes As Byte()
: Dim encoder As New UTF8Encoding()
: Dim md5Hasher As New MD5CryptoServiceProvider()
: Dim UserIDPassword As String
: Dim InitHashedPassword As Byte()
: Dim UserIDInitialPW As String
: Dim initialPassword As String
: Dim enteredPassword As String
:
: UserIDPassword = UserLogin.ToUpper & Password
: hashedBytes = md5Hasher.ComputeHash(encoder.GetBytes(UserIDPassword))
: enteredPassword = Me.ToHexString(hashedBytes)
:
: UserIDInitialPW = UserLogin.ToUpper & "password"
: InitHashedPassword = md5Hasher.ComputeHash(encoder.GetBytes(UserIDInitialPW))
: initialPassword = Me.ToHexString(InitHashedPassword)
: If enteredPassword = initialPassword Then
: initReturn = True
: End If
:
: Return initReturn
:
: End Function
:
: Public Function CheckUserPassword(ByVal UserLogin As String, ByVal Password As String) As Integer
: 'Dim objData As DataManager
: Dim objReturn As AgencyUser
: Dim intReturn As Integer
: Dim drReturn As SqlDataReader
: Dim hashedBytes As Byte()
: Dim encoder As New UTF8Encoding()
: Dim md5Hasher As New MD5CryptoServiceProvider()
: Dim UserIDPassword As String
: Dim enteredPassword As String
: Dim DBPassword As String
:
: UserIDPassword = UserLogin.ToUpper & Password
: hashedBytes = md5Hasher.ComputeHash(encoder.GetBytes(UserIDPassword))
: enteredPassword = Me.ToHexString(hashedBytes)
:
:
: cmdSQL.CommandText = "SELECT Agency_UserID, FirstName, LastName, LoginID, LoginPassword, Email, Active, AgencyID FROM BMS.dbo.AgencyUsers WHERE UPPER(LoginID) = '" & UserLogin.ToUpper & "' "
: drReturn = cmdSQL.ExecuteReader
: If drReturn.Read = True Then
: objReturn = New AgencyUser(Val(drReturn.GetValue(0).ToString), drReturn.GetValue(1).ToString, _
: drReturn.GetValue(2).ToString, drReturn.GetValue(3).ToString, drReturn.GetValue(4), _
: drReturn.GetValue(5).ToString, CBool(drReturn.GetValue(6).ToString), drReturn.GetValue(7).ToString)
: DBPassword = Me.ToHexString(objReturn.LoginPassword)
:
: If enteredPassword = DBPassword Then
: intReturn = CInt(drReturn.GetValue(0).ToString)
: Else
: intReturn = -1
: End If
: Else
: intReturn = -1
: End If
:
: drReturn.Close()
: drReturn = Nothing
: Return intReturn
:
: End Function
:
:
: #Region " CONSTRUCTORS AND DESTRUCTORS "
: Public Sub New(ByVal DatabaseServer As String, ByVal DatabaseCatalog As String, _
: ByVal DatabaseUsername As String, ByVal DatabasePassword As String)
: _ConnectionString = "Persist Security Info=False;User ID=" & DatabaseUsername & ";Initial Catalog=" & DatabaseCatalog & ";Data Source=" & DatabaseServer & ";Packet Size=4096;Password=" & DatabasePassword
: conSQL = New SqlConnection(_ConnectionString)
: 'conSQL.Open()
: 'cmdSQL = New SqlCommand
: 'cmdSQL.Connection = conSQL
: End Sub
:
: Public Sub Dispose()
: conSQL.Close()
: cmdSQL = Nothing
: conSQL = Nothing
: End Sub
: #End Region
:
:
: End Class
:
:
: This seems a bit further forward?
:
: Regards,
:
: Dr M.
:
**********************************************************************
First, I want to thank you again for your time. I just don't want this thing to beat me. There is a defined AgencyUser class but since we don't go that far I did'nt include it yesterday.
I have worked with what you gave me. I have even explored the list of available members. I have imported "System.Web.UI.WebControls". Below is the Page_Load code with comments on messages or values returned.
______________________________________________________________________
Imports System.Data.SqlClient
Imports System.Web.UI.WebControls
Partial Class Login
Inherits System.Web.UI.Page
Dim objData As DataManager
_______________________________________________________________________
Private Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load, Me.Load
Dim aAgencyList As New ArrayList
If Request.QueryString("LO") = "True" Then
Session.Clear()
End If
objData = New DataManager(ConfigurationManager.AppSettings("DatabaseServer"), _
ConfigurationManager.AppSettings("DatabaseCatalog"), ConfigurationManager.AppSettings("DatabaseUsername"), _
ConfigurationManager.AppSettings("DatabasePassword"))
' aAgencyList = objData.objReturnData . . . (Returned Nothing)
aAgencyList = objData.FetchActiveAgencies
Dim index As Integer = 0
Dim myControl As ListBox
myControl = Me.FindControl("lstAgency")
'Above returns nothing
Try
myControl.SelectionMode = ListSelectionMode.Single
Catch ex As Exception
''''' gets a Null Exception
End Try
'For index = 0 To aAgencyList(index)
' myControl.SelectedIndex = index
' myControl.SelectedValue = aAgencyList(index)
'Next
Login1.Controls.Item(0).DataBind()
End Sub