• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 187
  • Last Modified:

Send user name and pw to server

Hello,
I'm writing a perl script that should save an EE question to my hard disk (for practice. not sure I'll ever use it...). Now, I'm opening sockets and downloading and everything. The problem is that I must supply user name and password.

This is what I've tried:
print SOCKET "GET $page 1.0\nAuthorization: martinag password\n\n";

(no, that isn't my real password...:-))

I've tried a few solutions like this but I can't find the format to use when supplying user name and password.
Could you help me?

And by the way, is this secure? Is it just as secure as when I enter the information in my browser or should I do something (like using crypt) to get it more secure?

Martin
0
martinag
Asked:
martinag
  • 7
  • 3
  • 2
1 Solution
 
martinagAuthor Commented:
I've found something at ftp://ftp.ietf.org/internet-drafts/draft-ietf-http-authentication-03.txt about the Authentication-Info header. I guess I should use it, but I don't understand anything of it...

Martin
0
 
martinagAuthor Commented:
Ok, think I've understood a bit now...
I think I should
  print SOCKET "GET $page 1.0\nAuthorization: Basic $info\n\n";
where $info is "martinag:password", base64 encoded.

But how do I base64 encode?

Martin
0
 
jcondeCommented:
Hi, in order to do that you must
do the following:

fprintf (socket, "POST /your/page HTTP/1.0\n");
sprintf (tmp,"Authorization: Basic %s\n\n",base64_encode("username:password"));
fprintf (socket, tmp);

0
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

 
martinagAuthor Commented:
Where do I find base64_encode?

Martin
0
 
martinagAuthor Commented:
Your code seems like C. Is it? I'm using Perl...

Anyone know about a base 64 function for Perl?

Martin
0
 
b2piCommented:
perldoc MIME::Base64

(part of the LWP package, I think)

0
 
jcondeCommented:
Yes it is b2pi, its part of LWP :)
0
 
martinagAuthor Commented:
Ok, I visited www.perl.com and looked up LWP but I didn't find any MIME (not even Base64). Anyone got a URL?

Martin
0
 
b2piCommented:
0
 
martinagAuthor Commented:
I'll give the points to b2pi.

Great url you gave me. I've always wondered where to download all those modules.
BTW, it was http://perl.com/cgi-bin/cpan_mod?module=MIME::Base64 :-)

Martin
0
 
b2piCommented:
Great.  I love the multiplexor (in spite of my poor cut and paste skills) It also has the advantage of trying to find a server that's geographically (or at least network-wise) 'near' you, in order to increase speed.  You can get more info about it at http://language.perl.com/news/cpan-mux.html, and the source is at http://language.perl.com/misc/cpan_module

0
 
martinagAuthor Commented:
Thanks!

Martin
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Certified Penetration Testing

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

  • 7
  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now