473,396 Members | 2,108 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

What's wrong with this authenticate user code, please?

I have the following code but get a 'log on denied' error even though I know the user and password are correct.

Expand|Select|Wrap|Line Numbers
  1.  Private hashed As String
  2.  
  3.  Protected Sub LogonBtn_Click(sender As Object, e As EventArgs)
  4.  
  5.         'Dim hashedPassword As String = Crypto.HashPassword(hashed)
  6.  
  7.         Dim hashedPassword As String = Crypto.HashPassword(passwordTextBox.Text)
  8.  
  9.         'Authenticate user
  10.  
  11.         'Dim Authenticated As Boolean = Authenticate(strEmailTextBox.Text, passwordTextBox.Text)
  12.  
  13.         Dim Authenticated As Boolean = Authenticate(strEmailTextBox.Text, hashedPassword)
  14.  
  15.         'If authenticated, send user to userpage.aspx
  16.  
  17.         If Authenticated Then
  18.  
  19.             Dim target = String.Format("~/userpage.aspx?strEmailValue={0}", strEmailTextBox.Text)
  20.  
  21.             Session("strEmailValue") = strEmailTextBox.Text
  22.  
  23.             Response.Redirect(target, False)
  24.  
  25.         Else
  26.  
  27.             LabelError.Text = "Email/Password invalid. Login denied"
  28.  
  29.             LabelError.Visible = True
  30.  
  31.         End If
  32.  
  33.     End Sub
  34.  
  35.  
  36.     Protected Function Authenticate(strEmailValue As String, hashedValue As String) As Boolean
  37.  
  38.         'strEmailValue is the unknown email variable
  39.         'hashedValue is the unknown password variable
  40.         'strEmailTextBox is the ID of the email textbox field in my aspx file
  41.         'passwordTextBox is the ID of the password textbox field in my aspx file
  42.         'strEmail is the name of the email column in my MS Access database
  43.  
  44.         Using connection As OleDbConnection = New OleDbConnection(System.Configuration.ConfigurationManager.ConnectionStrings("students").ConnectionString)
  45.  
  46.             Dim cmdText As String = "SELECT COUNT(strEmail) FROM university WHERE strEmail = '" & strEmailValue & "' AND [hashed] = '" & hashedValue & "'"
  47.  
  48.             Dim cmd As New OleDbCommand(cmdText, connection)
  49.  
  50.             connection.Open()
  51.  
  52.             Dim result As Integer = cmd.ExecuteScalar
  53.  
  54.             connection.Close()
  55.  
  56.             Return result > 0
  57.  
  58.         End Using
  59.  
  60.     End Function
Thank for any advice.
Mar 8 '19 #1
0 1539

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: techy techno | last post by:
Hii I am trying to write down a cdont aplication which will email the survey form to the TO address with the answers checked by the user using the survey form I am 100% sure that there is...
0
by: Renato Neves | last post by:
The following code is working fine, i can create the user in the Active Directory and "enable" it. My problem is that, when i'm trying to authenticate him, i can't get to work!! The user and pass...
3
by: Litening | last post by:
Hi Can someone please supply me with a program (perhaps the C source) that authenticates a user on AIX (against the password/shadow/security file(s))? So far I have the following from IBM,...
1
by: aa | last post by:
When I am reading from local disk (d:), everithing is OK, but then I am reading from map disk I am geting the this error. Whats wrong. Thanks Server Error in '/Extra' Application....
5
by: taylan | last post by:
Hi Gurus, I have been working on my site pas few weeks almost 12 hrs a day. I came to a point and got stuck. I am hoping somebody can show me the way. What I want to do is: If a new user is visiting...
7
by: Mike Barnard | last post by:
It's a simple test... VERY SIMPLE. But... In an external stlyesheet some attributes don't show. With the same styles cut and pasted to the test internally it works as expected. Anyone tell...
2
by: Newbie1234 | last post by:
The code looks like this (got this from dev++ C tutorial): #include <stdio.h> main () { int num1, num2; printf("\nEnter first number "); scanf("%d",&num1);
1
by: ITHELP85 | last post by:
Hello I am trying to get a table attribute to calculate the result of 2 attribute in another table. I am using SQL Server 2005. I got another table to do this and it works fine, but the only...
2
by: rse2 | last post by:
Hello, I am having a little trouble with this code. I am trying to have it both Add and Subtract in the form. So far it is not displaying the answer to subtraction problems. Can you please give me a...
3
by: Priti Sharma | last post by:
string cat = Request.QueryString When I am using this code gives an error message as "NullReferenceException code Unhandlled by user code" Please reply.........
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.