c# - 从 URL 获取用户名和密码并粘贴到文本框中
解决方案
我首先想解决这样一个事实,即使用 URL 传递未加密的用户名和密码是各种不安全的。
但要解决你的问题。在 JavaScript 中,您可以使用window.location
. 这有多个您可以使用的字段。
window.location.host
并将window.location.hostname
返回“stackoverflow.com”
window.location.href
将返回整个 url “从 URL 中获取用户名和密码并粘贴到文本框中”
window.location.pathname
将返回host
“/questions/61336907/get-username-and-password-from-url-and-paste-into-text-box”之后的部分
window.location.search
如果这是 url 的一部分,将返回一个参数。“ https://stackoverflow.com?username=unsafe&password=password123 ”将返回“?username=unsafe&password=password123”。
然后,您将能够使用正则表达式从 url 获取用户名和密码。
const match = window.location.search.match( /username=(.*)&password=(.*)/g )
// results in array [ "username=unsafe&password=password123", "unsafe", "password123" ]
// first array item match[0] is the full match
// second item match[1] is the first group (you can create a group by using round brackets)
// third item match[2] is the second group
const username = match[1];
const password = match[2];
我不是正则表达式的明星,所以可能有比我建议的更好的解决方案。
但我希望这可以帮助你解决你的问题。
推荐阅读
- javascript - 在 React-Native 视图中根据纬度和经度定位对象而不显示实际地图
- flutter - 如何在颤动中将深色主题更改为所有页面
- state - 高级关联规则挖掘
- python-3.x - 使用 Selenium 刮玻璃门
- javascript - 如何在 WebRTC 流中显示每个接收到的帧?
- redis - redis,设置一个值为3,但它的类型是字符串
- spring-boot - 高 CPU 使用率和 ActiveMQ Artemis 中许多队列和会话的负载
- vim - 在 Vim 中的每一行末尾添加一个反斜杠
- laravel - Git-win10-laragon-权限被拒绝
- asp.net-mvc - 如果在响应标头中同时传递 X-Frame-options SAMEORIGIN 和 DENY 会发生什么?