Making a UNIX password in PHP

  • 15 years ago
    Hi again, I need to make a 13-character UNIX password using PHP so I can write a script to auto-manage a password file for use with one of my .htaccess files.

    I've spent a very long time trying to find one but all I've found so far is a similar script in CGI:
    Code:
    #!/usr/bin/perl
    # crypt.cgi  by David Efflandt, last updated 9/04/99
    # Crypts a password for use with web authentication

    use CGI qw/:standard :netscape/;
    srand( time() ^ ($$ + ($$ << 15)));

    print header,start_html('Crypt a Password'),"\n","\n";
    if(param()) {
       $word = param('word');
       @range = ('0'..'9','a'..'z','A'..'Z','.','/');
       $salt = $range[rand(int($#range)+1)] . $range[rand(int($#range)+1)];
       $pass = crypt($word, $salt);

       print h1("Result of crypt $word"),hr,'A crypted version of ',
           em($word),' is: ',em($pass),p,
           'Example of a line in a password file for web authentication '.
           '(colon separated):',p,pre("username:$pass"),hr;
    }

    print b("Note: "),a({href=>'crypt.txt'},'This Script'),
       ' works best when run on the system you need passords for because some
       systems use a more secure ',em('crypt'),' that ends up with more than the
       usual 13 character crypted password.';

    print start_form,center(table({border=>1,cellpadding=>10},
       Tr([th([("Crypt a Plain Text Password").br.textfield('word').br.submit])
       ]))),end_form,p,end_html;

    Normally I'd try and translate one to another bug not knowing any CGI I'm completely unable to in this case.

    Does anyone know of a script written in PHP I can use on my site please?

Post a reply

No one has replied yet! Why not be the first?

Sign in or Join us (it's free).

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“Any fool can write code that a computer can understand. Good programmers write code that humans can understand.” - Martin Fowler