CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
Search Posts SEARCH
Who's Online WHO'S
Log in LOG

Home: Perl Programming Help: Intermediate:
Get user credentials (HTTP Headers...)


New User

Jan 24, 2008, 11:00 AM

Post #1 of 1 (334 views)
Get user credentials (HTTP Headers...) Can't Post

Hello everyone. I'm new here.

I'm working on a piece of work to get the user credentials; username and host (on Intranet network).
After reading about HTTP headers and NTLM and I've determined that:

1. I need to force a "401 Unauthorized" status;
2- An "Authorization" header will be generated (Encoded in Base64).
3- Decode the "Authorization" header to extract the username and host.

Currently, I can force the status to 401. I cannot get the "Authorization" header. I'm fairly new with HTTP headers and NTLM. Any help would be appreciated.


use CGI;
use HTTP::Status;
use HTTP::Response;
use HTTP::Request;
use HTTP::Headers;
use LWP::UserAgent;

# Create New CGI Object
$cgi = new CGI;

# Print HTTP Header
print $cgi->header(-Title=>'asd');

# Force an Unauthorized Status
my $response = HTTP::Response->new(&HTTP::Status::RC_UNAUTHORIZED);

# Set WWW-Authenticate to NTLM
$response->header("WWW-Authenticate" => 'NTLM');

# Print the status line to make sure it's a 401 Unauthorized error
print $response->status_line;

# Get the Authorization Header
$auth = $response->header('Authorization');

# Print Base64 Encoded Authorization Header
print $auth;

# Decode
$auth = explode(' ', $value);
$auth = $auth[1];

if ($auth != Null) {
$auth = explode(':', base64_decode($auth));
$auth_username = $auth[0];

# Print Username
print $auth_username;



Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives