Browser Basic Auth mode authentication phpMyAdmin automatic Login

Source: Internet
Author: User
Tags auth chrome developer phpmyadmin

I. Demand
Login phpMyAdmin automatically. Eventually be able to resolve automatically log on to all Web pages that are authenticated using Basic Auth methods.

.
Two, phpMyAdmin four kinds of authentication landing way
1.config configuration file. Write the username and password that allows you to login directly in the config.inc.php configuration file.
2.cookie. The most commonly used way, by filling in the first form to login.
3.http. HTTP Basic authentication, using the browser's pop-up dialog box to log in. The main difference from the cookie approach is the user experience.
4.signon. Single sign-on, suitable for system integration. User login to a system, no longer need to lose the user name password that can be a key login phpMyAdmin.
Reference: Http://wiki.phpmyadmin.net/pma/Auth_types

The rationale signon approach should be the preferred solution to meet the needs, but the project development is always compromised and accommodating, to minimize interference in the operation of the existing system. In addition, in the implementation of Signon way to log in, but also need to retain the original user to lose user name password login mode, that is, standby login scheme. This complicates the problem.

Third, what is Basic Auth
The existing system uses the Basic Auth method, so I have studied how to be able to log in in this case also a key.

When accessing a URL that requires HTTP Basic authentication, if you do not provide a username and password, the server returns 401, and the browser prompts you for a username and password. Examples are as follows:

The code is as follows Copy Code
<?php
if (!isset ($_server[' Php_auth_user ')) {
Header (' Www-authenticate:basic realm= ' my Realm ');
Header (' http/1.1 401 Unauthorized ');
} else {
echo "<p>hello {$_server[' php_auth_user ']}.</p>";
echo "<p>you entered {$_server[' PHP_AUTH_PW ']} as your password.</p>";
}
?>

Save As login.php, browse http://localhost/login.php view effects.


Browser basic AUTH:IE9 and Chrome pop-up authentication dialog box
Enter the username password in the browser pop-up window, and if you use the Chrome Developer tool (or Firebug) to view it, you will find that it simply sends a request header similar to the following:

Authorization:basic bxlfdxnlcm5hbwu6bxlfcgfzc3dvcmq=
Four, Basic Auth certified Automatic Login Solution
In principle, there are 2 ways to pass Certification

• One is to add Authorization to the request header (which can be implemented using Javascript):
Authorization: "Basic user name and password base64 encrypted string"
• The second is to add a username and password in the URL (IE does not support):
http://username:password@domain.com/login.php

Use JS to add a request header can use XMLHttpRequest, the implementation code is as follows:

The code is as follows Copy Code

<title>login</title>
<script>
function Login () {
var username = document.getElementById ("username"). Value;
var password = document.getElementById ("password"). Value;

XHR = new XMLHttpRequest ();
Xhr.open ("POST", "http://localhost/login.php", false, username, password);
Xhr.send (NULL);

return xhr.status = = 200;
}
</script>
<body>
<form action= "http://localhost/login.php" method= "POST" onsubmit= "return login ();" >
<fieldset>
<legend>Login</legend>
<label for= "username" >username:</label>
<input type= "text" id= "username" name= "username" >

<label for= "Password" >password:</label>
<input type= "password" id= "password" name= "password" >

<input type= "Submit" value= "Subject" >
</fieldset>
</form>
</body>

Basic Auth Certified Automatic login solution, summed up--

1, the user name password directly written in the URL.

Disadvantage: Not safe enough, and IE does not support.

2, write a landing form, PHP will fill in the user name password in the form, and then the page onload JS generated Authorization request header submission

Disadvantage: This system and phpMyAdmin must be in the same domain. For example, the system in admin.domain.com, and phpMyAdmin in phpmyadmin.domain.com this case JS can not be submitted across the domain.

3, the system will post the user name password to the phpMyAdmin in the field of a form, the form and then take JS landing.

Disadvantage: You need to add a new page implementation cross-domain to the phpMyAdmin domain.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.