Visualizzazione dei risultati da 1 a 3 su 3
  1. #1
    Utente di HTML.it L'avatar di james
    Registrato dal
    Jun 2002
    Messaggi
    1,481

    funzione ENCRYPT di MySQL

    Ho creato queste due funzioni per crittare una password:
    Codice PHP:
    function vpopmail_RandomLTR() {
        
    $rnd rand(0,63);
        if (
    $rnd<26$retval chr($rnd+ord('a'));
        if (
    $rnd>25$retval chr($rnd-26+ord('A'));
        if (
    $rnd>51$retval chr($rnd-52+ord('0'));
        if (
    $rnd==62$retval ';';
        if (
    $rnd==63$retval '.';
        return 
    $retval;
    }

    function 
    vpopmail_RandomSalt() {
        
    $salt '$1$';
        for (
    $k=0$k<5$k++) {
            
    $salt .= vpopmail_RandomLTR();
        }
        
    $salt .= '0';
        return 
    $salt;
    }
    $boh vpopmail_RandomSalt();
    echo 
    "INSERT INTO tabella (password) VALUES (ENCRYPT('la_password','$boh'));"
    Così facendo genero la stringa SQL che si occupa di generare un account con la relativa password. Ora, come faccio a controllare la password che prendo da un form per verificare che sia guale a quella inserita nel db con la funzione ENCRYPT elaborata con quelle due funzioni?

  2. #2
    Utente di HTML.it L'avatar di james
    Registrato dal
    Jun 2002
    Messaggi
    1,481
    Nel manuale di MySQL ho trovato questo:
    ENCRYPT(str[,salt])
    Encrypt str using the Unix crypt() system call. The salt argument should be a string with two characters. (As of MySQL Version 3.22.16, salt may be longer than two characters.):

    mysql> SELECT ENCRYPT("hello"); -> 'VxuFAJXVARROc'

    If crypt() is not available on your system, ENCRYPT() always returns NULL. ENCRYPT() ignores all but the first 8 characters of str, at least on some systems. This will be determined by the behaviour of the underlying crypt() system call.



    Però non dice come validare una password salvata con ENCRYPT, sapete aiutarmi?

  3. #3
    Utente di HTML.it L'avatar di james
    Registrato dal
    Jun 2002
    Messaggi
    1,481
    up

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.