【问题标题】:How to authenticate my form using javascript如何使用 javascript 验证我的表单
【发布时间】:2011-07-12 16:34:00
【问题描述】:

那里

我需要在请求 url 之前进行身份验证,如果我使用 XMLHTTPRequest,一切正常

var xmlHttp = ...//some code goes here
xmlHttp.Open('POST','http://www.somesite.com/',false,userID,password);
xmlHttp.Send(null);

但如果我需要使用表格,如下所示

>var objForm = eval(formString);
>objForm.target='demoFrame'; //where demoFrame is an iFrame in another page
>objForm.action='http://www.somesite.com/';
>objForm.username.value=userID;
>objForm.password.value=password;
>objForm.method='post';
>objForm.submit();

但似乎 objForm 不能使用“用户名”和“密码”作为身份验证的输入,因为我不断收到来自主机站点的“身份验证失败”消息

有什么想法吗?

谢谢

【问题讨论】:

  • 出于好奇,为什么 JavaScript 中的 eval 如此糟糕?任何用户都可以使用 FireBug 或等效工具在网站上运行任何他想要的 JavaScript
  • @CodeMonkey:eval 可以允许攻击者在其他人的计算机上运行 Javascript(如果他可以修改字符串为 evald)。它也很慢。

标签: javascript forms authentication


【解决方案1】:

我假设其他站点正在使用 HTTP Basic 身份验证。

action 设置为'http://' + userId + ':' + password + '@www.somesite.com/'

【讨论】:

  • 我刚刚尝试过,但没有成功
  • 我很确定这是不可能的 a) 在许多浏览器中 b) 聪明,因为它在 url 中显示了用户名和密码
  • 或者我是否可以使用 XMLHTTPRequest 在 iframe 中打开页面?如果我必须使用 XMLHTTPRequest 进行身份验证...
  • @Leo:根据站点的不同,这可能是可能的。试试看。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2018-01-22
  • 1970-01-01
  • 2021-11-01
  • 1970-01-01
  • 2023-03-30
  • 1970-01-01
相关资源
最近更新 更多