Search code examples
perlhttpauthenticationcgibasic-authentication

how can i set username and password for basic http authentication?


i have a perl programm and used from cgi on it.i append the below line to the code

use CGI qw(:cgi);
print header(-type => 'text/html', -status => '401 Not Authorized',
         'WWW-Authenticate' => 'Basic realm="Videos"');

and when i enter the url browser wants username and password from me.problem is that i dont know what is user and password and where should i assign them. also any help with another mechanism to provide basic authentication would be good. can anyone help me with this? thanks.


Solution

  • Normally the webserver handles the basic authentication, and then it would probably also handle returning 401 for unauthorised requests - so your code id probably pointless.

    If you really want to try doing it yourself, you'll also have to parse the headers the browser sends when the user has tried to authenticate, validate the informatin using whatever method you like and return a useable page if successful.