Click to See Complete Forum and Search --> : Javascript Login
Hi guys,
I searched all over the web for a login script in JAVASCRIPT!! but all i could find is VBscripts. Can someone please help, i desperatly need a JS login script that links to an access database.
Thanks!
russell_g_1
03-22-2005, 06:33 AM
it should be almost the same as in vbscript. try downloading the windows script technologies documentation from microsoft and then converting a vbscript example. shouldn't be that bad at all. :)
tried that, i got nowhere! its why im looking for a plain JS script
here's the script i tried to convert
<%
'Declare variables
Dim oConnection, oRecordset, sSQL
Dim sUserName, sPassword
'Receive the form values and assign to sUserName and sPassword variables
sUsername = Request.Form("txtUsername")
sPassword = Request.Form("txtPwd")
If sUsername=sAdminUsername AND sPassword=sAdminpassword Then
Session("blnValidMember") = True
Session("Admin")=True
response.redirect "admin/approve.asp"
Else
'Create a connection odject and a recordset object
Set oConnection = Server.CreateObject("ADODB.Connection")
Set oRecordset = Server.CreateObject("ADODB.Recordset")
'Set an active connection to the Connection object
oConnection.Open sConnString
'Create a variable called sSQL which holds an SQL statement to query against the database
sSQL = "SELECT UserName, MembersPassword FROM tblMembers WHERE Username ='" & sUserName & "'" & _
" AND MembersPassword = '" & sPassword & "'"
'Query the database and return a recordset
oRecordset.Open sSQL, oConnection
'If the recordset finds a table row corresponding to the username and password entered - then valid login
If NOT oRecordset.EOF Then
'If its a valid login then set the session variable to True
Session("blnValidMember") = True
'redirect the user to the members.asp as they have logged in properly
Response.Redirect "members.asp"
Else
'if not valid username and password then set the session to false
Session("blnValidMember") = False
'Redirect to the no_access.asp - not a valid username and password
Response.Redirect "no_access.asp"
End If
'Close Objects and free up memory
oRecordset.Close
Set oRecordset = Nothing
oConnection.Close
Set oConnection=Nothing
End If
%>
russell_g_1
03-22-2005, 07:18 AM
here you go.
<%@ language="jscript" %>
<%
var sAdminUsername = "username";
var sAdminpassword = "password";
var sConnString = "DATABASE=login;UID=sa;PWD=qwertyuiop;DSN=login";
var oConnection, oRecordset, sSQL;
var sUsername = Request("txtUsername");
var sPassword = Request("txtPwd");
if (sUsername==sAdminUsername && sPassword==sAdminpassword)
{
Session("blnValidMember") = true;
Session("Admin")=true;
//Response.redirect("admin/approve.asp");
Response.write("admin access");
}
else
{
oConnection = Server.CreateObject("ADODB.Connection");
oRecordset = Server.CreateObject("ADODB.Recordset");
sSQL = "SELECT UserName, MembersPassword FROM tblMembers WHERE Username ='" + sUsername + "'";
sSQL = sSQL + " AND MembersPassword = '" + sPassword + "'";
oConnection.Open(sConnString);
oRecordset.Open(sSQL, oConnection);
if (!oRecordset.EOF)
{
Session("blnValidMember") = true;
//Response.Redirect("members.asp");
Response.write("member access");
}
else
{
Session("blnValidMember") = false;
//Response.Redirect("no_access.asp");
Response.write("no access");
}
oRecordset.Close;
oRecordset = null;
oConnection.Close;
oConnection = null;
}
%>
:)