.htpasswd reading and comparing with mysql

Discussion in 'Web Design and Development' started by Cabbit, Jul 11, 2010.

  1. Cabbit macrumors 68020

    Cabbit

    Joined:
    Jan 30, 2006
    Location:
    Scotland
    #1
    For a user login(this does sound daft i know) i want to compare the username in htpasswd with the username in my database in order to allow logins.

    Does anyone know how to read the usernames in the htpasswd file for comparing them with my database. I was thinking it would be converting it to xml or something first.
     
  2. angelwatt Moderator emeritus

    angelwatt

    Joined:
    Aug 16, 2005
    Location:
    USA
    #2
    Well this command line command will give you a list of user names.
    Code:
    cat .htpasswd | sed -e s'/^\([_a-z]*\).*$/\1/'
    You could use that to go line by line and compare in the DB.
     
  3. Cabbit thread starter macrumors 68020

    Cabbit

    Joined:
    Jan 30, 2006
    Location:
    Scotland
    #3
    It ended up i had to add my cgi bin to the php base path and then building the contents of the file into an array splitting it by :

    PHP:
    $htfile '/var/www/vhosts/mydomain.com/cgi-bin/8pewPo7kZ6gdEYArjS3s9GQhyNn5BFzu/password/.htpasswd'
    $res = Array(); 
    foreach(
    file($htfile) as $l

    $array explode(':',$l); 
    $user $array[0]; 
    $pass chop($array[1]); 
    $res[$user] = $pass

     

Share This Page