jeg har min hjemmeside liggende hos freepaq.dk, på deres nye server, jeg skal bruge .htacces til at passwordbeskytte en mappe, og har installeret samme version af Apache på min egen maskine, som de har på deres servere. Når jeg genererer en htpasswd fil i htpasswd.exe som ligger i Apache og uploader den på servere´n, vil den ikke godtage mit password, jeg har kontaktet freepaq, og de siger at jeg skal lave et perlscript til kryptering, da det er smartest at gøre det på serveren, da det så skulle virke. Jeg forsøgte mig først med php´s md5(), men den løsning virkede desværre ikke, og da jeg ikke er en ørn til perl, prøver jeg her, og belønner bedste forslag med 150 points.
Det her godt nok i php, og jeg har ikke testet det: <HTML> <HEAD> <TITLE>HTPASSWD Password Generator</TITLE> </HEAD>
<BODY BGCOLOR=\"white\">
<H1>HTACCESS password generator</H1>
<? //////////////////// // This script uses PHP\'s crypt() function. This function depends on the // underlying OS having that capability. Linux and FreeBSD do. Windows does // not. Therefore, this script will not run correctly under Windows. ////////////////////
//////////////////// // Check to see if we have the required fields //////////////////// if ($user && $pass) {
//////////////////// // Specify the valid characters for a salt value. This is a-z, A-Z, 0-9, // the period \'.\' and the forward slash \'/\'. //////////////////// $saltchars = array( \'a\',\'b\',\'c\',\'d\',\'e\',\'f\',\'g\',\'h\',\'i\',\'j\',\'k\',\'l\',\'m\', \'n\',\'o\',\'p\',\'q\',\'r\',\'s\',\'t\',\'u\',\'v\',\'w\',\'x\',\'y\',\'z\', \'A\',\'B\',\'C\',\'D\',\'E\',\'F\',\'G\',\'H\',\'I\',\'J\',\'K\',\'L\',\'M\', \'N\',\'O\',\'P\',\'Q\',\'R\',\'S\',\'T\',\'U\',\'V\',\'W\',\'X\',\'Y\',\'Z\', \'1\',\'2\',\'3\',\'4\',\'5\',\'6\',\'7\',\'8\',\'9\',\'0\',\'.\',\'/\' );
//////////////////// // Seed the randomizer with a suitably random value //////////////////// srand((double)microtime()*1000000);
//////////////////// // Set the variable PHP uses to determine the encryption type for DES // encryption and generate the 2 digit salt. //////////////////// $CRYPT_STD_DES = 1; $saltcount = 2; for ($i=0; $i<$saltcount; $i++) { $des_salt .= $saltchars[rand(0,count($saltchars))]; }
//////////////////// // Generate the DES encrypted password //////////////////// $des_encrypted = crypt($password,$des_salt);
//////////////////// // Set the variable PHP uses to determine the encryption type for MD5 // encryption and generate the 8 digit salt. The MD5 salt actually consists // of 12 characters which always start with \'$1$\' and ends with a \'$\'. //////////////////// $CRYPT_MD5 = 1; $saltcount = 8; $md5_salt = \"\\$1\\$\"; for ($i=0; $i<$saltcount; $i++) { $md5_salt .= $saltchars[rand(0,count($saltchars))]; }
Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.