Visualizzazione dei risultati da 1 a 5 su 5
  1. #1

    script login riconosce solo il primo record!

    Salve a tutti, il mio problema è questo:
    ho scaricato uno script per loggarsi all'interno di alcune pagine protette come admin e lo ho adattato affinchè riconoscesse una password criptata md5 all'interno di un db access.
    Il problema però è che mi riconosce solo il primo tra gli utenti presenti nella tabella TB_UTENTI e non i successivi ovvero solo il primo record nonostante che nella query gli abbia specificato SELECT * FROM TB_UTENTI.
    Come posso risolvere?
    Il codice è il seguente:

    <%

    Option Explicit

    '--- Prevent caching
    Response.Buffer = True
    Response.ExpiresAbsolute = Now() - 1
    Response.AddHeader "cache-control", "must-revalidate"
    Response.AddHeader "cache-control", "private"
    Response.AddHeader "pragma", "no-cache"
    Session.Timeout = 20
    %>


    <%
    Dim cn
    Set cn = Server.CreateObject("ADODB.Connection")
    cn.Open strDB
    Dim rs
    Set rs = Server.CreateObject("ADODB.Recordset")
    Dim strSql
    strSQL="SELECT * FROM TB_UTENTI"
    rs.Open strSQL,cn

    '--- Define variables
    Dim sReferer, sGoBackTo, sUserName, sPassword, bLoginSuccessful, Error
    Dim UserName, Password

    UserName = rs("user")
    Password = rs("pass")

    if request.querystring("comebackto") <> "" then
    sReferer = request.querystring("comebackto")
    sGoBackTo = "?" & request.querystring
    end if

    '--- If Login Form has been submitted
    if request.form("Status") = "FormSubmitted" then
    sUserName = replace(request.form("txtUserName"),"'","")
    sPassword = replace(MD5(request.form("txtPassword")),"'","")

    '--- Check for username and password match
    If (sUserName = UserName) AND (sPassword = Password) then
    bLoginSuccessful = True
    Else
    bLoginSuccessful = False
    Error = "Username o password errati!"
    '--- Send user to the default page after 3 unsuccessful try
    Session("count") = Session("count") + 1
    if Session("count") > 3 then
    Session.abandon
    response.redirect sGoBackTo
    End if
    End if
    Session("bLoginSuccessful") = bLoginSuccessful
    End if

    '--- After a successful login, let's send the user back to see the protected page
    '--- The variable sReferer holds the page to go back,
    '--- if it is empty, the user is redirected to the default page
    if bLoginSuccessful Then
    if sReferer = "" then
    response.redirect "../"
    else
    response.redirect sReferer
    end if
    else

    '--- If no login performed then display the Login Form
    %>

    <link rel="stylesheet" type="text/css" href="stile.css">
    <table width="743" border="0" align="center" cellpadding="0" cellspacing="10" bgcolor="#000000">
    <tr>
    <td class="cerca">
    <p align=center>
    <font size="2" color="#FFD80C">Per entrare nell area di modifica è necessario effettuare il riconoscimento!</font>

    </p>
    </td>
    </tr>
    <tr>
    <%

    '--- Show error when credentials are incorrect
    if Error <> "" then
    response.write "<td colspan=2 align=center class=cerca bgcolor=#000000><font color=red size=2>" & Error
    response.write "</font>

    </td></tr><tr>"
    End if

    %>
    <td align="center" height="80" class="cerca">
    <form action="login.asp<%=sGoBackTo%>" method="post" name="Login">
    <table border="0" cellpadding="2" cellspacing="0" bgcolor="#000000" class="cerca"><tr>
    <td align="right"><font color="red">*</font>User name:</td>
    <td><input type="Text" name="txtUserName" size="30" class="inputclass"></td>
    </tr><tr>
    <td align="right"><font color="red">*</font>Password:</td>
    <td><input type="Password" name="txtPassword" size="30" class="inputclass"></td>
    </tr><tr>
    <td colspan="2" height=30 class=cerca align=right>
    <input type="submit" name="cmdLogin" value="Login" class="buttonclass">
    <input type="hidden" name="Status" value="FormSubmitted">
    </td></tr></table>



    </p><div align="center">Torna alla Home</div>

    </p></form></td></tr>

    </table>

    <%End if

    Rs.close
    set Rs = nothing

    cn.close
    set cn = nothing

    %>


    Grazie 1000 a chiunque voglia darmi una mano!

  2. #2
    Ciao,

    devi mettere nella query user e password altrimenti non ci sono riferimenti e logicamente ti prende il primo record:
    Codice PHP:
    sUserName replace(request.form("txtUserName"),"'","")
    sPassword replace(MD5(request.form("txtPassword")),"'","")
    strSQL " SELECT * FROM TB_UTENTI WHERE user ='"sUserName &"' AND pass = '"sPassword &"' " 
    fulvio.

  3. #3
    Grazie infinite per la risposta celerissima Fulviolo!

    Il problema adesso però è che se mantengo la stessa struttura del codice e cambio solo la query mi restituisce l'errore:

    Il record corrente corrisponde all'inizio o alla fine del file oppure è stato eliminato.

    se invece provo a mettere la query dopo le righe che hai indicato tu invece:

    Tipo non corrispondente

    Come dovrebbe essere la struttura? Grazie ancora!

  4. #4
    ma... più o meno:

    recuperi user e password (meglio se passati in post e non in get, quindi Request.Form("xxxx") )

    se non sono vuote
    - fai i replace
    - apri la connessione al DB
    - scrivi la query
    - la esegui
    - se RS non è EOF (If Not RS.EOF Then)
    -- recuperi i dati dell'utente
    -- ci fai quello che vuoi
    - altrimenti ' se RS è EOF
    -- visualizzi un messaggio che user o password non corrispondono
    - chiudi la connessione al DB
    altrimenti ' se user e password sono vuote
    - visualizzi un messaggio di errore

    più o meno la logica è questa...

    fulvio.

  5. #5
    Grazie 1000, ce l'ho fatta!

    Se può servire a qualcuno il codice è questo:

    Codice PHP:
    <%

    Option Explicit

    '--- Prevent caching
    Response.Buffer = True
    Response.ExpiresAbsolute = Now() - 1
    Response.AddHeader "cache-control", "must-revalidate"
    Response.AddHeader "cache-control", "private"
    Response.AddHeader "pragma", "no-cache"
    Session.Timeout = 20
    %>


    <%

    '
    --- Define variables
    Dim sReferer
    sGoBackTosUserNamesPasswordbLoginSuccessfulError

    if request.querystring("comebackto") <> "" then
        sReferer 
    request.querystring("comebackto")
        
    sGoBackTo "?" request.querystring
    end 
    if

    '--- If Login Form has been submitted
    if request.form("Status") = "FormSubmitted" then
        sUserName = replace(request.form("txtUserName"),"'","")
            sPassword = replace(MD5(request.form("
    txtPassword")),"'","")

    Dim cn
    Set cn = Server.CreateObject("ADODB.Connection")
    cn.Open strDB
    Dim rs
    Set rs = Server.CreateObject("ADODB.Recordset")
    Dim strSql
    strSQL="SELECT * FROM TB_UTENTI WHERE user ='"& sUserName &"' AND pass = '"& sPassword &"'"  
    rs.Open strSQL,cn

    '
    --- Check for username and password match
        
    If not rs.EOF then
            bLoginSuccessful 
    True
    Rs
    .close
    set Rs 
    nothing

    cn
    .close
    set cn 
    nothing        
        
    Else
            
    bLoginSuccessful False
            Error 
    "Username o password errati!"
        '--- Send user to the default page after 3 unsuccessful try
            Session("count") = Session("count") + 1
            if Session("count") > 3 then 
                Session.abandon
                response.redirect sGoBackTo
            End if
        End if
        Session("bLoginSuccessful") = bLoginSuccessful
    End if

    '
    --- After a successful loginlet's send the user back to see the protected page
    '
    --- The variable sReferer holds the page to go back,
    '---  if it is empty, the user is redirected to the default page
    if bLoginSuccessful Then
        if sReferer = "" then
            response.redirect "../"
        else
            response.redirect sReferer
        end if
    else
    '
    --- If no login performed then display the Login Form
    %>

    <
    link rel="stylesheet" type="text/css" href="stile.css">
    <
    table width="743" border="0" align="center" cellpadding="0" cellspacing="10" bgcolor="#000000">
    <
    tr>
    <
    td class="cerca">
    <
    p align=center>
    [
    b]<font size="2" color="#FFD80C">Per entrare nell area di modifica è necessario effettuare il riconoscimento!</font>[/b]

    </
    p>
    </
    td>
    </
    tr>
    <
    tr>
    <%
    '--- Show error when credentials are incorrect 
    if Error <> "" then
        response.write "<td colspan=2 align=center class=cerca bgcolor=#000000><font color=red size=2>" & Error
        response.write "</font>

    </td></tr><tr>"
    End if
    %>
    <td align="center" height="80" class="cerca">
    <form action="login.asp<%=sGoBackTo%>" method="post" name="Login">
    <table border="0" cellpadding="2" cellspacing="0" bgcolor="#000000" class="cerca"><tr>
    <td align="right">[b]<font color="red">*</font>User name:[/b]</td>
    <td><input type="Text" name="txtUserName" size="30" class="inputclass"></td>
    </tr><tr>
    <td align="right">[b]<font color="red">*</font>Password:[/b]</td>
    <td><input type="Password" name="txtPassword" size="30" class="inputclass"></td>
    </tr><tr>
    <td colspan="2" height=30 class=cerca align=right>
    <input type="submit" name="cmdLogin" value="Login" class="buttonclass">
    <input type="hidden" name="Status" value="FormSubmitted">
    </td></tr></table>



    </p><div align="center">[b][url="default.asp"]Torna alla Home[/url][/b]</div>

    </p></form></td></tr>

    </table>

    <% End if

    %> 

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.