Current location: Hot Scripts Forums » Programming Languages » ASP.NET » login control help..


login control help..

Reply
  #1 (permalink)  
Old 04-22-08, 11:09 PM
chazze06 chazze06 is offline
Newbie Coder
 
Join Date: Apr 2008
Location: Pangasinan, Philippines
Posts: 21
Thanks: 0
Thanked 0 Times in 0 Posts
Unhappy login control help..

i don;t know how to make a login control.. and i don't know how will make it work.. can someone help me.. my databse is an excel file..where the username and passwords are stored.. there will be 2 catgeries of a users, an ADMIN and a USER.. pls help.. i really dont know what to do..
Reply With Quote
  #2 (permalink)  
Old 04-23-08, 10:00 AM
digioz's Avatar
digioz digioz is offline
Community VIP
 
Join Date: Oct 2003
Location: Chicago, IL
Posts: 2,171
Thanks: 3
Thanked 9 Times in 9 Posts
ASP.NET 2.0 comes with a login control:

ASP_NET_Login_Control.jpg

Or are you asking for the whole system (coding included)?


Pete
__________________
Reply With Quote
  #3 (permalink)  
Old 04-24-08, 10:00 PM
chazze06 chazze06 is offline
Newbie Coder
 
Join Date: Apr 2008
Location: Pangasinan, Philippines
Posts: 21
Thanks: 0
Thanked 0 Times in 0 Posts
yes.. i don't know how to code.. i don't understand how ASP.net 2.0 works.. i'm really having a hard time figuring it out really..
Reply With Quote
  #4 (permalink)  
Old 04-25-08, 12:58 PM
digioz's Avatar
digioz digioz is offline
Community VIP
 
Join Date: Oct 2003
Location: Chicago, IL
Posts: 2,171
Thanks: 3
Thanked 9 Times in 9 Posts
Here is a very simple example on how to do this.

Database:

Type: Microsoft Excel
File Name: users.xls
Sheet Name: users

users.gif

Login WebForm Code:

HTML Code:
<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="login.aspx.vb" Inherits="SimpleLogin._Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:Login ID="Login1" runat="server">
        </asp:Login>
    
    </div>
    </form>
</body>
</html>
Login Code Behind:

vb.net Code:
  1. Imports System.Data.OleDb
  2. Partial Public Class _Default
  3.     Inherits System.Web.UI.Page
  4.     Private Shared lsConnectionString As String
  5.     Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
  6.         Dim lsPath As String = Request.PhysicalApplicationPath & "users.xls"
  7.         lsConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & lsPath & ";Extended Properties=Excel 8.0;"
  8.     End Sub
  9.     Protected Sub Login1_Authenticate(ByVal sender As System.Object, ByVal e As System.Web.UI.WebControls.AuthenticateEventArgs) Handles Login1.Authenticate
  10.         Dim lsQuery As String = "SELECT * FROM [users$]"
  11.         Dim loConnection = New OleDbConnection(lsConnectionString)
  12.         Dim loCommand As New OleDbCommand(lsQuery, loConnection)
  13.         Dim lsUsername, lsPassword, lsUserType As String
  14.         Dim loReader As IDataReader
  15.         loConnection.Open()
  16.         loReader = loCommand.ExecuteReader()
  17.         While (loReader.Read())
  18.             lsUsername = CStr((loReader("username")))
  19.             lsPassword = CStr((loReader("password")))
  20.             lsUserType = CStr((loReader("usertype")))
  21.             If Login1.UserName = lsUsername AndAlso Login1.Password = lsPassword Then
  22.                 Response.Write("Login Successful!")
  23.                 e.Authenticated = True
  24.                 Session("Authenticated") = True
  25.                 Session("username") = lsUsername
  26.                 Session("password") = lsPassword
  27.                 Session("usertype") = lsUserType
  28.                 Response.Redirect("Default.aspx")
  29.                 Exit While
  30.             End If
  31.         End While
  32.     End Sub
  33. End Class

Success Web Form:

HTML Code:
<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="Default.aspx.vb" Inherits="SimpleLogin._Default1" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    
    </div>
    </form>
</body>
</html>
Success Code Behind:

vb.net Code:
  1. Public Partial Class _Default1
  2.     Inherits System.Web.UI.Page
  3.     Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
  4.         If Session("Authenticated") = True Then
  5.             Response.Write("Welcome " & Session("username") & "!<br />")
  6.             Response.Write("User Type: " & Session("usertype"))
  7.         Else
  8.             Response.Redirect("Login.aspx")
  9.         End If
  10.     End Sub
  11. End Class

Sample Project is attached bellow. I hope this helps!


Pete
Attached Files
File Type: zip SimpleLogin.zip (46.5 KB, 110 views)
__________________
Reply With Quote
  #5 (permalink)  
Old 04-26-08, 02:55 AM
chazze06 chazze06 is offline
Newbie Coder
 
Join Date: Apr 2008
Location: Pangasinan, Philippines
Posts: 21
Thanks: 0
Thanked 0 Times in 0 Posts
sir digioz.. thank you for the sample project.. i'll try this when i get home.. i'll post some questions again when i don't understand it.. thanks a lot1
Reply With Quote
  #6 (permalink)  
Old 05-08-08, 01:58 AM
chazze06 chazze06 is offline
Newbie Coder
 
Join Date: Apr 2008
Location: Pangasinan, Philippines
Posts: 21
Thanks: 0
Thanked 0 Times in 0 Posts
sir digioz.. uhm.. how would i make a web.config?.. i used the excel but i had a problem making a delete query so i changed back to access.. how do i make an authentication?.. for example, a user can't access the other pages if he/she is not logged in.. the page should redirect him/her to the login page.. thanks for the sample code.. it was really helpful.. uhm can u give another sample, this time using c#? thanks again! ÜÜ
Reply With Quote
  #7 (permalink)  
Old 05-08-08, 10:00 AM
digioz's Avatar
digioz digioz is offline
Community VIP
 
Join Date: Oct 2003
Location: Chicago, IL
Posts: 2,171
Thanks: 3
Thanked 9 Times in 9 Posts
Read the section marked "Success Code Behind" above. The same applies for Microsoft Access as far as checking to see if the user is logged in or not.

Pete
__________________
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
login, roles problem dbrook007 ASP.NET 10 11-10-06 03:42 PM
Login Script v1.9 Problem SuavyDoodle JavaScript 8 09-28-06 09:13 PM
Difference between the user control and Custom server controls bhar ASP.NET 0 07-22-06 05:42 AM
login control forms/test salvo PHP 1 01-03-06 03:16 AM
SHOUTCAST HOSTING CONTROL PANEL $14.99 /month! The Long Awaited Software Has Arrived! SCPanel General Advertisements 0 09-21-05 11:05 PM


All times are GMT -5. The time now is 02:36 PM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.