29 messaggi dal 30 agosto 2018
Buongiorno, in fase di registrazione utente faccio un semplice controllo sul database per vedere se l'utente è già presente sul database:
Function checkusername(username)
  Dim ConnACCESS
  Set ConnACCESS = Apri_DB()
  stringa = "SELECT USERNAME FROM UTENTI WHERE USERNAME='" & username & "'"
  set T_Tab = Server.CreateObject("ADODB.Recordset")
  set T_Tab = ConnACCESS.Execute(stringa)
  if not T_Tab.eof then
    successo = 0
    user_error = "class='error'"
    stringaerrore = "L'username inserito è già stato usato."
  end if
  T_Tab.close
  Chiudi_DB(ConnACCESS)
End Function

il problema è che quando invio il form il controllo non ritorna niente.
html:
<div>
    <input type="checkbox" name="privacypolicy"><label style="font-weight: bold;">Ho letto e accetto i <a href="/terms.asp">Termini e le Condizioni</a> d'uso.</label>
</div><%checkusername(request.form("username"))%>
<div style="text-align: right;">
<input type="submit" class="button round" name="registrati" value="CONTINUA" onclick="return checksign();">
              </div>
11.886 messaggi dal 09 febbraio 2002
Contributi
Ciao,
purtroppo il codice che hai postato non è sufficiente per capire il problema.

Vedo che dalla funzione checkusername stai valorizzando le variabili successo, user_error e stringaerrore ma non si vedono i punti in cui usi queste variabili.
Dovresti mostrare anche il campo input che porta l'attributo name="username"

ciao,
Moreno

Enjoy learning and just keep making
29 messaggi dal 30 agosto 2018
Ciao, posto il codice integrale:
Dim ConnACCESS
        Set ConnACCESS = Apri_DB()
        stringa = "SELECT PASSWORD FROM UTENTI WHERE USERNAME='" & sistema_err_sql(Request.Form("username")) & "' OR EMAIL = '"&request.form("username")&"'"
        Set T_Tab = Server.CreateObject("ADODB.Recordset")
        Set T_Tab = ConnACCESS.Execute(stringa)
        if not T_Tab.eof then
          if request.form("password") = T_Tab("PASSWORD") then
            stringa = "SELECT * FROM UTENTI WHERE USERNAME='" & sistema_err_sql(Request.Form("username")) & "' OR EMAIL = '"&request.form("username")&"' AND PASSWORD = '"&sistema_err_sql(request.form("password"))&"'"
            Set T_Tab = ConnACCESS.Execute(stringa)
            if not T_Tab.eof then
              Dim utente(2)
              utente (0) = T_Tab.FIELDs("NOME")
              utente (1) = T_Tab.FIELDs("COGNOME")
              session("utente") = utente
              session("auth") = T_Tab.FIELDs("AUTH")
              for i = 0 to ubound(utente)
                utente(i) = null
              next
              successo = 1
            end if
          else
            if request.form("password") = empty then
              successo = 0
              pw_error = "class='error'"
              stringaerrore = "Devi inserire una password."
            else
              successo = 0
              pw_error = "class='error'"
              stringaerrore = "La password inserita non è corretta."
            end if
          end if
        else
          successo = 0
          user_error = "class='error'"
          stringaerrore = "L'username inserito non è corretto."
        end if
        Chiudi_DB(ConnACCESS)
        if successo = 1 then
          if session("auth") = 0 then
            response.redirect "/admin/login.asp"
            response.end
          end if
        end if
      end if
    end if
    Sub checkusername(username)
      Dim ConnACCESS
      Set ConnACCESS = Apri_DB()
      stringa = "SELECT USERNAME FROM UTENTI WHERE USERNAME='"&username&"'"
      set T_Tab = Server.CreateObject("ADODB.Recordset")
      set T_Tab = ConnACCESS.Execute(stringa)
      if not T_Tab.eof then
        successo = 0
        user_error = "class='error'"
        stringaerrore = "L'username inserito è già stato usato."
      end if
      T_Tab.close
      Chiudi_DB(ConnACCESS)
    End sub%>
    <div class="large-12" style="text-align: -webkit-center;">
      <table style="background-color: #ffffff;">
        <tbody>
          <td>
            <form name="accedi" action="loginprova.asp" method="post">
              <div>
                <input type="radio" name="action" value="login" onclick="this.form.submit()"<%if request.form("action") = "login" or request.form("action") = "" then%>checked<%end if%>>Login:
              </div><%if request.form("action") = "login" or request.form("action") = "" then%>
              <span id="showerror" class="radius alert label" style="text-align:left;<%if successo = 0 then%>display: block;<%else%>display: none;<%end if%>"><%=stringaerrore%></span>
              <div>
                <label id="username" <%=user_error%> style="font-weight: bold;">USERNAME/E-MAIL:</label>
              </div>
              <div>
                <input type="text" name="username" placeholder="Inserisci il nome utente o l'e-mail.">
              </div>
              <div>
                <label id="password" <%=pw_error%> style="font-weight: bold;">PASSWORD:</label>
              </div>
              <div>
                <input type="password" name="password" placeholder="Inserisci la password...">
              </div>              
              <div style="text-align: right;">
                <input type="submit" class="button round" name="valida" value="ACCEDI" onclick="return checkaccess();">
              </div>                
              <%end if%>
              <div>
                <input type="radio" name="action" value="registrati" onclick="this.form.submit()"<%if request.form("action") = "registrati" then%>checked<%end if%>>Registrati:
              </div>
              <%if request.form("action") = "registrati" then%>
              <span id="showerror" class="radius alert label" style="text-align:left;<%if successo = 0 then%>display: block;<%else%>display: none;<%end if%>"><%=stringaerrore%></span>
              <div>
                <label for="nome" id="nome" style="font-weight: bold;">NOME:</label>
              </div>
              <div>
                <input type="text" name="nome" placeholder="Inserisci il tuo nome.">
              </div>
              <div>
                <label for="cognome" id="cognome" style="font-weight: bold;">COGNOME:</label>
              </div>
              <div>
                <input type="text" name="cognome" placeholder="Inserisci il tuo cognome.">
              </div>
              <div>
                <label for="email" id="email" style="font-weight: bold;">E-MAIL:</label>
              </div>
              <div>
                <input type="text" name="email" placeholder="Inserisci la tua e-mail">
              </div>
              <div>
                <label for="telefono" id="telefono" style="font-weight: bold;">TELEFONO:</label>
              </div>
              <div>
                <input type="text" name="telefono" placeholder="Inserisci il tuo telefono.">
              </div>
              <div>
                <label for="username" id="username" <%=user_error%> style="font-weight: bold;">USERNAME:</label>
              </div>
              <div>
                <input type="text" name="username" placeholder="Inserisci il tuo nome utente.">
              </div>
              <div>
                <label for="password" id="password" style="font-weight: bold;">PASSWORD:</label>
              </div>
              <div>
                <input type="password" name="password" placeholder="Inserisci la tua password.">
              </div>
              <div>
                <label for="conferma_password" id="conferma_password" style="font-weight: bold;">CONFERMA PASSWORD:</label>
              </div>
              <div>
                <input type="password" name="conferma_password" placeholder="Reinserisci la password.">
              </div>
              <div>
                <input type="checkbox" name="newsletter"><label style="font-weight: bold;">Acconsento all'invio di mail per fini commerciali.</label>
              </div>
              <div>
                <input type="checkbox" name="privacypolicy"><label style="font-weight: bold;">Ho letto e accetto i <a href="/terms.asp">Termini e le Condizioni</a> d'uso.</label>
              </div><%checkusername(request.form("username"))%>
              <div style="text-align: right;">
                <input type="submit" class="button round" name="registrati" value="CONTINUA" onclick="return checksign();">
              </div>

sistema_err_sql semplicemente contiene la sintassi del repalce.
Modificato da Thebest il 23 aprile 2019 19:35 -
11.886 messaggi dal 09 febbraio 2002
Contributi
Ciao, dovresti invocare la Sub checkusername PRIMA di stampare il form di registrazione.
Cioè qui:

<%
if request.form("action") = "registrati" then
  checkusername(request.form("username"))
%>


In questo modo, la Sub checkusername valorizzerà le variabili successo, user_error e stringaerrore, in modo che i loro valori possano essere usati nelle successive righe di codice, ad esempio nella span "showerror" in cui visualizzi l'errore.

ciao,
Moreno

Enjoy learning and just keep making
29 messaggi dal 30 agosto 2018
Grazie, non ci avevo proprio fatto caso, ti faccio un altra domanda, è possibile che il controllo dell'username in fase di registrazione non funzioni, perché provando a registrarmi con un username precedentemente inserito nel db non mi da nessun errore come invece dovrebbe darmi. Non capisco dove sta l'inghippo.
11.886 messaggi dal 09 febbraio 2002
Contributi
Prova a stampare a video la query SQL che ti serve a verificare se lo username esiste già. Così puoi capire quale query viene inviata (e se viene inviata). Ho inserito un Response.Write qui in mezzo.

    Sub checkusername(username)
      Dim ConnACCESS
      Set ConnACCESS = Apri_DB()
      stringa = "SELECT USERNAME FROM UTENTI WHERE USERNAME='" & sistema_err_sql(username) & "'"
      Response.Write(stringa)
      'set T_Tab = Server.CreateObject("ADODB.Recordset") <-- Questa riga la puoi rimuovere
      set T_Tab = ConnACCESS.Execute(stringa)


ciao,
Moreno
Modificato da BrightSoul il 24 aprile 2019 10:24 -

Enjoy learning and just keep making
29 messaggi dal 30 agosto 2018
Ciao, la stringa sql è giusta, il replace era sbagliato, l'ho sostituito con un request, ma i tre valori successo user_error e stringaerrore non vengono inizializati se l'utente esiste già nel db.
Set ConnACCESS = Apri_DB()
      stringa = "SELECT USERNAME FROM UTENTI WHERE USERNAME='"&request.form("username")&"'"
      response.write stringa
      set T_Tab = ConnACCESS.Execute(stringa)
      if not T_Tab.eof then
        successo = 0
        user_error = "class='error'"
        stringaerrore = "Esiste già un account con questo username."
      end if
      response.write T_Tab.fields("USERNAME")
      T_Tab.close
      Chiudi_DB(ConnACCESS)

Modificato da Thebest il 24 aprile 2019 11:55 -
11.886 messaggi dal 09 febbraio 2002
Contributi
Le variabili successo, user_error e stringaerrore le hai definite con Dim, da qualche parte? Definiscile in cima al file, in modo che assumano uno scope globale.
'In cima al file asp metti:
Dim successo
Dim user_error
Dim stringaerrore


ciao,
Moreno


l'ho sostituito con un request

Occhio che così sei esposto alla Sql Injection e al relativo rischio che qualcuno ti disintegri il database.
Modificato da BrightSoul il 24 aprile 2019 12:16 -

Enjoy learning and just keep making

Torna al forum | Feed RSS

ASPItalia.com non è responsabile per il contenuto dei messaggi presenti su questo servizio, non avendo nessun controllo sui messaggi postati nei propri forum, che rappresentano l'espressione del pensiero degli autori.