Developer's Guide :: Using BasicAuthentication
BasicAuthentication provides authentication by using HTTP protocol. You can use it by following this steps:
Contents |
Place a BasicAuthentication component in your Page
Drag and drop a BasicAuthentication component to your Page or create it in runtime, this is a non-visible component.
Setup the UserName and Password properties
Setup the UserName and Password properties to the valid combination to provide access to that page, if you need more than a single combination user/password, use the OnAuthenticate event, in which you can authenticate the user querying a table or having a list of valid combinations by code.
Generate the event handler for the OnBeforeShow event of the Page
The right event to use the component is the OnBeforeShow event of the Page, so it's there where we are going to request valid credentials.
Call the execute method the BasicAuthentication component
function AdminBeforeShow($sender, $params) { $this->BasicAuthentication1->Execute(); }
Now, if you run your script, you will get a browser window requesting you for valid user/password, there are several properties, like ErrorMessage and Title, you can use to tweak the behaviour of the component.
I just noticed that even though I had magic_quotes turned on for my server, it does NOT protect the basic authentication so make sure and do that protection yourself.
Sample authenticate:
function BasicAuthentication1Authenticate($sender, $params) { if (isset($params['username'])) { $name=mysql_real_escape_string($params['username']); $password=mysql_real_escape_string($params['password']); $query="select * FROM `userdata` WHERE `user` = '".$name."'"; $result=mysql_query($query); //if (!$result) {deleted custom code} $row=mysql_fetch_array($result); $customercode=$row['cuscode']; if (($name==$row['user']) && ($password==$row['pass'])) { return (true); } return (false); } return (false); }