Register Register Member Login Member Login Member Login Forgot Password ??
PHP , ASP , ASP.NET, VB.NET, C#, Java , jQuery , Android , iOS , Windows Phone
 

Registered : 109,027

HOME > ASP > ASP Authentication > ASP User Authentication/Login From Database



Clound SSD Virtual Server

ASP User Authentication/Login From Database

ASP User Authentication From Database ตัวอย่างการใช้งาน Authentication ตรวจสอบค่า User และ Password จากฐานข้อมูล Microsoft Access


Syntax

Response.Status = "401 Unauthorized"
Response.AddHeader "WWW-Authenticate","Basic Realm=""localhost"""


AspAuthDatabaseCheck.asp

<%
'*** Function Decode Authentication Code ***'
	Function Decode(strCode)
		
		Dim UUEncode,i,OffSet,numBytes,byteGroup,groupBytes
		Dim CharCounter,thisChar,thisByte,k
		Set UUEncode = Server.CreateObject("Scripting.Dictionary")
		For i=0 To 63
			Select Case i
			Case 0 OffSet = 65
			Case 26 OffSet = 71
			Case 52 OffSet = -4
			End Select
			UUEncode(Chr(i+OffSet)) = i
		Next

		For byteGroup = 1 To Len(strCode) Step 4
			numBytes = 3
			groupBytes = 0
			For CharCounter = 0 to 3
				thisChar = Mid(strCode,byteGroup+CharCounter,1)
				If thisChar = "=" Then
				numBytes = numBytes - 1
				thisByte = 0
				Else
				thisByte = UUEncode(thisChar)
				End If
				groupBytes = 64*groupBytes+thisByte
			Next

			For k = 1 To numBytes
				Select Case k
				Case 1: thisChar = groupBytes \ 65536
				Case 2: thisChar = (groupBytes And 65535) \ 256
				Case 3: thisChar = (groupBytes And 255)
				End Select
				Decode = Decode & Chr( thisChar )
			Next
		Next
	End Function
	'*** End Function Decode Authentication Code ***'
	
	Dim strAuth,authSplit,strUser,strPassword

	Sub subAuthentication()
		Response.Clear()
		Response.Status = "401 Unauthorized"
		Response.AddHeader "WWW-Authenticate","Basic Realm=""localhost"""
		Response.end
	End Sub


	IF Trim(Request.ServerVariables("HTTP_AUTHORIZATION")) <> "" Then
		strAuth = Request.ServerVariables("HTTP_AUTHORIZATION")
		strAuth = Trim(Mid(strAuth,6))
		strAuth = Decode(strAuth)
		authSplit = Split(strAuth,":")

		strUser = authSplit(0)
		strPassword = authSplit(1)
		
		If Trim(strUser) = "" Or Trim(strPassword) = "" Then
			Call subAuthentication()
		Else


		'*** Check From Database ***'

		Dim Conn,strSQL,objRec
		Set Conn = Server.Createobject("ADODB.Connection")
		Conn.Open "DRIVER=Microsoft Access Driver (*.mdb);DBQ=" & Server.MapPath("mydatabase.mdb"),"" , ""
		strSQL = "SELECT * FROM user WHERE User = '"&strUser&"' AND Password = '"&strPassword&"' "
		Set objRec = Conn.Execute(strSQL)
		If objRec.EOF Then
			Call subAuthentication()
		Else
				Session("strUser") = strUser
				Session("strPassword") = strPassword
		End If
		objRec.Close()
		Conn.Close()
		Set objRec = Nothing
		Set Conn = Nothing
		
	End If
	
	If Session("strUser") = "" Or Session("strPassword") = "" Then
			Call subAuthentication()
	End IF

%>



AspAuthenticationDatabase1.asp

<!--#include file="AspAuthCheck.asp"-->
<html>
<head>
<title>ThaiCreate.Com ASP & Authentication</title>
</head>
<body>
<%
	Response.write("<center><h1>Welcome "&Session("strUser")&" </h1><br><br><h2>Now Page 1</h2><center>")
%>
<center><a href="AspAuthenticationDatabase2.asp">Page 2</a><center>
</body>
</html>



AspAuthenticationDatabase2.asp

<!--#include file="AspAuthCheck.asp"-->
<html>
<head>
<title>ThaiCreate.Com ASP & Authentication</title>
</head>
<body>
<%
	Response.write("<center><h1>Welcome "&Session("strUser")&" </h1><br><br><h2>Now Page 2</h2><center>")
%>
<center><a href="AspAuthenticationDatabase1.asp">Page 1</a><center>
</body>
</html>


คำอธิบาย
จากตัวอย่างถ้าผู้ใช้เปิดไฟล์ AspAuthenticationDatabase1.asp หรือ AspAuthenticationDatabase2.asp ถ้ายังไม่ผ่านการ Login โปรแกรมจะให้ทำการกรอก User/Password โดยนำข้อมูลไปเช็คใน MySQL ว่ามี User และ Password หรือไม่ ถ้ามีให้ทำการบันทึกเป็นค่า Session เพื่อนำไปใช้งานต่อไป

Screenshot

ASP & Authenticate

ASP & Authenticate






   
Share


ช่วยกันสนับสนุนรักษาเว็บไซต์ความรู้แห่งนี้ไว้ด้วยการสนับสนุน Source Code 2.0 ของทีมงานไทยครีเอท


ลองใช้ค้นหาข้อมูล


   


Bookmark.   
       
  By : ThaiCreate.Com Team (บทความเป็นลิขสิทธิ์ของเว็บไทยครีเอทห้ามนำเผยแพร่ ณ เว็บไซต์อื่น ๆ)
  Score Rating :  
  Create/Update Date : 2008-10-30 23:46:08 / 2010-11-08 12:14:03
  Download : Download  ASP User Authentication/Login From Database
 Sponsored Links / Related

 
ASP User Authentication
Rating :

 
ASP User Authentication Simple Text files
Rating :

 
ASP User Authentication Active Directory (AD)
Rating :


ThaiCreate.Com Forum


Comunity Forum Free Web Script
Jobs Freelance Free Uploads
Free Web Hosting Free Tools

สอน PHP ผ่าน Youtube ฟรี
สอน Android การเขียนโปรแกรม Android
สอน Windows Phone การเขียนโปรแกรม Windows Phone 7 และ 8
สอน iOS การเขียนโปรแกรม iPhone, iPad
สอน Java การเขียนโปรแกรม ภาษา Java
สอน Java GUI การเขียนโปรแกรม ภาษา Java GUI
สอน JSP การเขียนโปรแกรม ภาษา Java
สอน jQuery การเขียนโปรแกรม ภาษา jQuery
สอน .Net การเขียนโปรแกรม ภาษา .Net
Free Tutorial
สอน Google Maps Api
สอน Windows Service
สอน Entity Framework
สอน Android
สอน Java เขียน Java
Java GUI Swing
สอน JSP (Web App)
iOS (iPhone,iPad)
Windows Phone
Windows Azure
Windows Store
Laravel Framework
Yii PHP Framework
สอน jQuery
สอน jQuery กับ Ajax
สอน PHP OOP (Vdo)
Ajax Tutorials
SQL Tutorials
สอน SQL (Part 2)
JavaScript Tutorial
Javascript Tips
VBScript Tutorial
VBScript Validation
Microsoft Access
MySQL Tutorials
-- Stored Procedure
MariaDB Database
SQL Server Tutorial
SQL Server 2005
SQL Server 2008
SQL Server 2012
-- Stored Procedure
Oracle Database
-- Stored Procedure
SVN (Subversion)
แนวทางการทำ SEO
ปรับแต่งเว็บให้โหลดเร็ว


Hit Link
   







Load balance : Server 01
ThaiCreate.Com Logo
© www.ThaiCreate.Com. 2003-2024 All Rights Reserved.
ไทยครีเอทบริการ จัดทำดูแลแก้ไข Web Application ทุกรูปแบบ (PHP, .Net Application, VB.Net, C#)
[Conditions Privacy Statement] ติดต่อโฆษณา 081-987-6107 อัตราราคา คลิกที่นี่