/    Sign up×
Community /Pin to ProfileBookmark

Login Failed Error Message

Hi,

I would like to display a message when a user fails to login to say, incorrect username or password. Its currently setup to redirect the user to the same login page on fail and even puts an error code attached to the login address.

I have also set up an absoluetely positioned div with the error message in it and the css style attached to this div is set to visibility ‘hidden’

My question is where in the code and how do I tell the div css to not be hidden so that the message appears when a user fails to login?

Thanks

Lloyd

[B]Javascript at top of page:[/B]

<%
// *** Validate request to log in to this site.
var MM_LoginAction = Request.ServerVariables(“URL”);
if (Request.QueryString != “”) MM_LoginAction += “?” + Server.HTMLEncode(Request.QueryString);
var MM_valUsername = String(Request.Form(“username”));
if (MM_valUsername != “undefined”) {
var MM_fldUserAuthorization = “”;
var MM_redirectLoginSuccess = ” index-1.asp”;
var MM_redirectLoginFailed = “index.asp?err=1”;

var MM_loginSQL = “SELECT username, Password”;
if (MM_fldUserAuthorization != “”) MM_loginSQL += “,” + MM_fldUserAuthorization;
MM_loginSQL += ” FROM dbo.tblMember WHERE username = ? AND Password = ?”;
var MM_rsUser_cmd = Server.CreateObject (“ADODB.Command”);
MM_rsUser_cmd.ActiveConnection = MM_iiGymConectionString_STRING;
MM_rsUser_cmd.CommandText = MM_loginSQL;
MM_rsUser_cmd.Parameters.Append(MM_rsUser_cmd.CreateParameter(“param1”, 200, 1, 50, MM_valUsername)); // adVarChar
MM_rsUser_cmd.Parameters.Append(MM_rsUser_cmd.CreateParameter(“param2”, 200, 1, 50, Request.Form(“password”))); // adVarChar
MM_rsUser_cmd.Prepared = true;
var MM_rsUser = MM_rsUser_cmd.Execute();

if (!MM_rsUser.EOF || !MM_rsUser.BOF) {
// username and password match – this is a valid user
Session(“MM_Username”) = MM_valUsername;
if (MM_fldUserAuthorization != “”) {
Session(“MM_UserAuthorization”) = String(MM_rsUser.Fields.Item(MM_fldUserAuthorization).Value);
} else {
Session(“MM_UserAuthorization”) = “”;
}
if (String(Request.QueryString(“accessdenied”)) != “undefined” && false) {
MM_redirectLoginSuccess = Request.QueryString(“accessdenied”);
}
MM_rsUser.Close();
Response.Redirect(MM_redirectLoginSuccess);
}
MM_rsUser.Close();
Response.Redirect(MM_redirectLoginFailed);
}
%>

[B]HTML:[/B]
<div id=”loginerror”>Incorrect username or password</div>

[B]Style Sheet:[/B]

#loginerror {
position:absolute;
width:220px;
height:30px;
z-index:3;
top: 135px;
font-size: 12px;
color: #FF0000;
left: 15px;
font-weight: bold;
visibility: hidden;
}

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@Angry_Black_ManAug 13.2007 — Javascript at top of page:[/quote]

sorry, thats ASP not javascript.

so what you do is create a javascript that is on the page, that looks into the URL bar for the error code (as a get variable), and then if it exists, innerHTML it to your div as appropriate.

but since youre working in ASP, it would be better to stick some ASP code in there that figures out if there was a login error, and if so simply spits out an logon error message. at that point, you remove all the need for javascript, espeically considering what you posted doesnt have any anyways. why add more languages if you dont have to, you know?

oh, and if you find my explanation doesnt fit your needs, it is best to repost this in the ASP forums without the whole javascript spin. youll get a solution in no time im sure!
Copy linkTweet thisAlerts:
@lloydmavauthorAug 13.2007 — wow, what an idiot I am,

sorry I will repost this on the asp forum
×

Success!

Help @lloydmav spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.19,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...