loginform.html
codice:
<form method="post" action="login.asp">
username <input type="text" name="username" />
password <input type="password" name="password" />
<input type="submit" value="invia" />
</form>
login.asp
codice:
<%
errore = false
username = trim(request.form("username"))
password = trim(request.form("password"))
username = replace(username,"'","''")
password = replace(password,"'","''")
if len(username) > 0 and len(username) > 0 then
set conn = server.createObject("ADODB.Connection")
conn.open connectionString ' al posto di connectionString metti la tua stringa di connessione
sql = "SELECT [username] FROM tabellaUtenti WHERE [username] = '" & username & "' AND [password] = '" & password & "'"
set rs = conn.execute(sql)
if rs.eof then
errore = true
messaggio = "Login errato!"
else
session("username") = rs("username")
session("userLogged") = true
end if
rs.close
set rs = nothing
conn.close
set conn = nothing
else
errore = true
messaggio = "I campi sono obbligatori!"
end if
if not errore then response.redirect "benvenuto.asp"
%>
<html>
<head>
<title></title>
</head>
<body>
<%=messaggio%>
</body>
</html>
benvenuto.asp
codice:
<%
' questa riga di codice va messa in tutte le pagine protette da login
if not session("userLogged") then response.redirect "loginform.html"
' questo controllo si occupa di ritrovare il nome dell'utente loggato
' se nessun utente è loggato allora apparirà il nome visitatore
if len(session("username")) > 0 then
utente = session("username")
else
utente = "visitatore"
end if
%>
<hrml>
<head>
<title></title>
</head>
<body>
Benvenuto <%=utente%>
</body>
</html>
A te ora comprendere ed adattare.
In bocca al lupo!