通过发送形式基本身份验证信息 [英] Sending basic authentication information via form

查看:165
本文介绍了通过发送形式基本身份验证信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的工作,目前使用基本身份验证对话框登录系统的站点,也就是说,如果你去这里你得到对话框的类型:<一href=\"http://www.dur.ac.uk/vm.boatclub/password/index.php\">http://www.dur.ac.uk/vm.boatclub/password/index.php
我没有设置该系统并在一个位置,很容易/快速地解决它我不是,但它确实工作。然而,问题是,对话框不告诉你什么登录,你必须使用(即它的用户名和密码组合)的信息,所以我想用一种形式来代替它非常有帮助。我一直在想,这是不可能的,但我想问才能找到答案。

I am working on a site that currently uses a basic authentication dialog box login system, that is the type of dialog that you get if you go here: http://www.dur.ac.uk/vm.boatclub/password/index.php I did not set this system up and am not in a position to easily/quickly work around it, but it DOES work. The issue however is that the dialog box is not very helpful in telling you what login information you have to use (that is which username and password combination), and so I would like to replace it with a form. I had been thinking that this wasn't possible but I wanted to ask in order to find out.

是否有可能建立该数据发送到服务器,使得它接受它以同样的方式,这将使用此对话框HTML表单?或者是否有可能建立一个PHP脚本,将采取正常的表单数据,并以某种方式处理它,它传递到服务器,这样它会在?

Is it possible to set up an HTML form that sends the data to the server such that it accepts it in the same way that it would using this dialog box? Alternatively is it possible to set up a PHP script that would take normal form data and process it somehow passing it to the server such that it logs in?

编辑:被告知后,这是我绕到并设法找到工作,并保持在持续登录的用户的方式基本身份验证然而,这并不在Internet Explorer中运行。解决的办法是简单地将用户重定向到:
<一href=\"http://username:password@www.dur.ac.uk/vm.boatclub/password/index.php\">http://username:password@www.dur.ac.uk/vm.boatclub/password/index.php
但是,Internet Explorer中删除它因钓鱼使用大约3年前。有没有办法使用JavaScript来让浏览器访问该网站这样的方式?或将我要简单地改变我的UI?

After being told that this is basic authentication I went around and have managed to find a way that works and keeps the user persistently logged in. However, this does not work in internet explorer. The solution was simply to redirect the user to: http://username:password@www.dur.ac.uk/vm.boatclub/password/index.php But Internet Explorer removed it due to phishing uses about 3 years ago. Is there a way to use javascript to get the browser to access the site in this way? Or will I have to simply change my UI?

推荐答案

研究公平一点,我发现,在这两种浏览器和IE浏览器的工作方式后,这是所有我在测试,但逻辑在code不建议它应该打破任何地方。正是基于此文章在:

After a fair bit of research I found a way that works in both Chrome and IE, that is all that I've tested it in, but the logic of the code does not suggest it should break anywhere. It is based upon this article:

<一个href=\"http://www.peej.co.uk/articles/http-auth-with-html-forms.html\">http://www.peej.co.uk/articles/http-auth-with-html-forms.html

这是相当深入,但问题的症结所在是这样的 - 在表格上提交你做一个AJAX请求到基本身份验证的文件夹。 AJAX请求可以接受基本身份验证的用户名和密码信息,一旦浏览器已经authed一旦它的授权在那个境界,也就是说,它会保持登录状态。在previous文章做它的纯JavaScript,所以要加其他的东西比简单地说明连杆这里的使用jQuery(希望相当透明)实现:

Which is rather in depth but the crux of it is this - on the form submit you make an AJAX request into the basic authenticated folder. AJAX requests can accept username and password information for basic auth, and once the browser has authed once it's authorised in that realm, i.e. it will stay logged in. The previous article does it in pure javascript, so to add something other than simply explaining the link here's a (hopefully fairly transparent) implementation using jQuery:

  $(document).ready(function()
  {
    $('#loginForm').submit(function()
    {
      var username = $('#usernameInput').val();
      var password = $('#passwordInput').val();

      $.ajax(
        {
          'password' : password,
          'username' : username,
          'url'      : 'http://www.website.com/basic-auth-file.php',
          'type'     : 'GET',
          'success'  : function(){ window.location = 'http://www.website.com/basic-auth-file.php'; },
          'error'    : function(){ alert('Bad Login Details');},
        }
      );

      return false;
    });
  });

这实现了我想要的东西,而且是比较简单易懂,但是我将恳请任何人谁想要这个走出去,不知道基本身份验证出去做研究!

This achieved what I wanted, and is relatively simple to understand, however I would implore anyone who wanted this to go out and didn't know about basic auth to go out and do the research!

这篇关于通过发送形式基本身份验证信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆