开发者

Autofill a username and password

开发者 https://www.devze.com 2023-01-04 05:21 出处:网络
I would like to be able to click a link开发者_运维问答 in Website A that will autofill a username and password into Website B.

I would like to be able to click a link开发者_运维问答 in Website A that will autofill a username and password into Website B.

Can anybody provide me some ideas how to do this with JavaScript or PHP?

Many thanks!


I am not sure what you mean by your question. Have you tried looking at OpenSocial or OpenID?


If you're able to edit website B, you can try to add a query string contains username and password to link and on website B get them from url and echo into input field's value attribute.

#Sample url on website A:
http://www.example.com/?username=admin&password=1234

#Simple sample form on website B:
<form>
    <input type="text" value="<?php echo $_GET['username']; ?>" />
    <input type="password" value="<?php echo $_GET['password']; ?>" />
    <input type="submit" />
</form>


As someone else mentioned before the cleanest solution is to use a credential token.

  1. User logs in on Site A.
  2. Site A inserts a credential token in Site B's database - either by directly contacting the database of Site B or by calling a URL or an API in the background. This credential token will contain a unique token identifier (usually a long string, possibly obtained from md5-ing something) and the username and password of the user on Site B.
  3. When the user is presented links to Site B on Site A all of them end with &token=123456789abcdef0
  4. When the user arrives on Site B and the URL contains the token mentioned, username and password are extracted from the token in Site B's database and prefilled in the login box.

Tweak this to your liking.

0

精彩评论

暂无评论...
验证码 换一张
取 消