Pagina 1 di 3 1 2 3 ultimoultimo
Visualizzazione dei risultati da 1 a 10 su 25

Discussione: Codice random doppio

  1. #1
    Utente di HTML.it L'avatar di [trodat]
    Registrato dal
    Oct 2004
    Messaggi
    2,135

    Codice random doppio

    Ciao a tutti.

    Nonostante abbia messo un controllo per la verifica della presenza del nr_autorizzazione, (un controllo che se già presente nella tabella Gest genera un secondo codice nr_autorizzazione), ho sempre il problema che anche quando viene generato un secondo codice questo potrebbe essere già presente, causando confusione.

    Cosa posso fare?


    codice:
    nr_autorizzazione = request.form("nr_autorizzazione")
    
    Sql = "SELECT * from Gest where NR_AUTORIZZAZIONE = '"& NR_AUTORIZZAZIONE &"'"
    Set objRS = Server.CreateObject("ADODB.Recordset")
    objRS.Open SQL, conn, 3, 3
    
    if NOT objRS.eof then
    
       nr_autorizzazione = request.form("nr_autorizzazione")
       
    else
    
    Function RandomPW(myLength)
    	Const minLength = 6
    	Const maxLength = 20
    	
    	Dim X, Y, strPW
    	
    	If myLength = 0 Then
    		Randomize
    		myLength = Int((maxLength * Rnd) + minLength)
    	End If
    	
    	For X = 1 To myLength
    		Y = Int((3 * Rnd) + 1) '(1) Numeric, (2) Uppercase, (3) Lowercase
    		
    		Select Case Y
    			Case 1
    				Randomize
    				strPW = strPW & CHR(Int((9 * Rnd) + 48))
    			Case 2
    				Randomize
    				strPW = strPW & CHR(Int((25 * Rnd) + 65))
    			Case 3
    				Randomize
    				strPW = strPW & CHR(Int((25 * Rnd) + 97))
    		End Select
    	Next
    	
    	RandomPW = strPW
    End Function
    
    strfinal = RandomPW(10)
    
       nr_autorizzazione = strfinal
       
    end if
    Lo Stato dà un posto. L’impresa privata dà un lavoro. – Indro Montanelli

  2. #2
    codice:
    function IsPresente(stringa)
    
    Sql = "SELECT * from Gest where NR_AUTORIZZAZIONE = '"& stringa &"'"
    Set objRS = Server.CreateObject("ADODB.Recordset")
    objRS.Open SQL, conn, 3, 3
    
      IsPresente = objRsw.eof
    
      objrs.close
      set objRs = nothing
    end function
    
    
    
    Function RandomPW(myLength)
    	Const minLength = 6
    	Const maxLength = 20
    	
    	Dim X, Y, strPW
    	
    	If myLength = 0 Then
    		Randomize
    		myLength = Int((maxLength * Rnd) + minLength)
    	End If
    	
    	For X = 1 To myLength
    		Y = Int((3 * Rnd) + 1) '(1) Numeric, (2) Uppercase, (3) Lowercase
    		
    		Select Case Y
    			Case 1
    				Randomize
    				strPW = strPW & CHR(Int((9 * Rnd) + 48))
    			Case 2
    				Randomize
    				strPW = strPW & CHR(Int((25 * Rnd) + 65))
    			Case 3
    				Randomize
    				strPW = strPW & CHR(Int((25 * Rnd) + 97))
    		End Select
    	Next
           if IsPresente(strPW) then
                 RandomPW = RandomPW(myLength)
           else
    	    RandomPW = strPW
           end if
    End Function
    Sono così maledettamente attraente...

    QuickChat. (Asp e ajax)

  3. #3
    Utente di HTML.it L'avatar di [trodat]
    Registrato dal
    Oct 2004
    Messaggi
    2,135
    Scusa ma non capisco cosa cambia...
    Lo Stato dà un posto. L’impresa privata dà un lavoro. – Indro Montanelli

  4. #4
    hops, scusa

    codice:
    function IsPresente(stringa)
    
    Sql = "SELECT * from Gest where NR_AUTORIZZAZIONE = '"& stringa &"'"
    Set objRS = Server.CreateObject("ADODB.Recordset")
    objRS.Open SQL, conn, 3, 3
    
      IsPresente = NOT objRsw.eof
    
      objrs.close
      set objRs = nothing
    end function
    Sono così maledettamente attraente...

    QuickChat. (Asp e ajax)

  5. #5
    dunque, la funzione che genera il codice fa direttamente il controllo nel database. e richiama se stessa se il codeice è già presente. è ricorsiva. prova
    Sono così maledettamente attraente...

    QuickChat. (Asp e ajax)

  6. #6
    Utente di HTML.it L'avatar di [trodat]
    Registrato dal
    Oct 2004
    Messaggi
    2,135
    Ma al posto di questo cosa devo mettere se lo sostituisci con stringa?:

    codice:
    nr_autorizzazione = request.form("nr_autorizzazione")
    e poi perchè:

    codice:
    objRsw.eof
    e non

    codice:
    objRs.eof
    ???
    Lo Stato dà un posto. L’impresa privata dà un lavoro. – Indro Montanelli

  7. #7
    dopo le funzioni scrivi


    codice:
    function isPresente(stringa)
    ...
    end function
    
    Function RandomPW(myLength)
    ...
    end function
    
    
    nr_autorizzazione = request.form("nr_autorizzazione")
    
    if isPresente(nr_autorizzazione) then
              nr_autorizzazione = RandomPW(10)
    end if
    Sono così maledettamente attraente...

    QuickChat. (Asp e ajax)

  8. #8
    Originariamente inviato da [trodat]
    Ma al posto di questo cosa devo mettere se lo sostituisci con stringa?:

    codice:
    nr_autorizzazione = request.form("nr_autorizzazione")
    e poi perchè:

    codice:
    objRsw.eof
    e non

    codice:
    objRs.eof
    ???

    errore di battitura. il l'oggetto è ObjRs
    Sono così maledettamente attraente...

    QuickChat. (Asp e ajax)

  9. #9
    Utente di HTML.it L'avatar di [trodat]
    Registrato dal
    Oct 2004
    Messaggi
    2,135
    Grazie, sembra funzionare correttamente.
    Lo Stato dà un posto. L’impresa privata dà un lavoro. – Indro Montanelli

  10. #10
    Utente di HTML.it L'avatar di [trodat]
    Registrato dal
    Oct 2004
    Messaggi
    2,135
    Non funziona !!!!
    Mi ha creato gli stessi codici random...
    Lo Stato dà un posto. L’impresa privata dà un lavoro. – Indro Montanelli

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.