Re: Send Login and Password to URL

Posted by webmaster Guido on July 12, 2003

In Reply to: Send Login and Password to URL posted by JB on July 12, 2003

: How do I sent a login string and password string from a link on a Menu Item?

Let's set up a form with 3 Edit boxes:

- edLogin: for the login;
- edPassword: for the password;
- edPage: for the address of the page (without the "http://" part).

Additionally, there's a button to initiate the login, named btnLogin, and there's a label named lblReturn, to show if there was an error.

The code for the OnClick event of the button for accessing a password protected webpage is as follows:

procedure TForm1.btnLoginClick(Sender: TObject);
var
  Login, Password, WebPage, LogText: string;
  Return: integer;
begin
  Login := edLogin.Text;
  Password :=edPassword.Text;
  WebPage := edPage.Text;
  LogText := 'http://' + Login + ':' + Password + '@' + Webpage;
  Return := ShellExecute(Handle, 'open', PChar(LogText), nil, nil, SW_SHOW);
  // If Return > 32 then it's OK, otherwise there was an error
  // For values of Return, see: API help, ShellExecute
  if Return > 32 then
    lblReturn.Caption := 'OK, done'
  else
    lblReturn.Caption := IntToStr(Return);
end;
Example: to access http://www.test.com with the login "abc" and the password '123', you would enter this in the edit-boxes:

- edLogin: abc
- edPassword: 123
- edPage: www.test.com

NOTE: add "SHELLAPI" to the USES statement of the form, otherwise Delphi won't find the ShellExecute function.


Related Articles and Replies:


Find related articles

Search for:  shellexecute


Delphi Forum :: Tutorials :: Source code :: Tips