如何解决在 wordpress 中自动重置密码python 请求或其他方式
我正在尝试衡量使用默认 WordPress 方法重置用户密码的速度。 WordPress 首先要求提供电子邮件或用户名,然后发送指向该用户电子邮件的链接。如果您点击链接,它会将您重定向到一个页面(“localhost/wordpress_5_4_2_try3/wp-login.php?action=rp”),您必须在其中为该用户插入新密码。它看起来像这样: Provide new password image (default content on the password field)
我能够对 WordPress 代码进行一些小的更改(例如,我更改了 wp_mail 功能,因此不发送邮件并在特定文件中添加了一些激活链接的存储)。我需要对许多试图同时更改密码的用户进行实验。我已经使用 Selenium 编写了关于它的代码,但这不是我想要的,因为它很慢。我试图找出是否有更快的解决方案(通过 python 请求库或其他库/工具/语言)。我对不同的想法持开放态度。您可以在下面找到我已经尝试过的内容:
1)
import requests
s=requests.Session()
info = {'pass1':'a_password#38'}
url1 = "http://localhost/wordpress_5_4_2_try3/wp-login.php?action=rp&key=theKey&login=user_name"
url2 = "http://localhost/wordpress_5_4_2_try3/wp-login.php?action=rp"
r = s.get(url1)
r2 = s.post(url1,data=info)
r3 = requests.post(url2,data=info)
-
我尝试了 1 的许多版本。例如,在其中一些版本中,我没有使用 r,只使用了 r2,其他一些我没有使用 r3。我相信我的问题来自于它被重定向到给我表格的事实。您可以在此处找到我使用 print(r2.text) 时得到的回复,以防万一:
<!--[if IE 8]> <html xmlns="http://www.w3.org/1999/xhtml" class="ie8" lang="en-US"> <![endif]--> <!--[if !(IE 8) ]><!--> <html xmlns="http://www.w3.org/1999/xhtml" lang="en-US"> <!--<![endif]--> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>Reset Password ‹ wordPrSite3 — WordPress</title> <link rel='dns-prefetch' href='//s.w.org' /> <script> var userSettings = {"url":"\/wordpress_5_4_2_try3\/","uid":"0","time":"1621286619","secure":""}; </script> <script src='http://localhost/wordpress_5_4_2_try3/wp-includes/js/utils.min.js?ver=5.4.6'></script> <script src='http://localhost/wordpress_5_4_2_try3/wp-includes/js/jquery/jquery.js?ver=1.12.4-wp'></script> <script src='http://localhost/wordpress_5_4_2_try3/wp-includes/js/jquery/jquery-migrate.min.js?ver=1.4.1'></script> <script> var _zxcvbnSettings = {"src":"http:\/\/localhost\/wordpress_5_4_2_try3\/wp-includes\/js\/zxcvbn.min.js"}; </script> <script src='http://localhost/wordpress_5_4_2_try3/wp-includes/js/zxcvbn-async.min.js?ver=1.0'></script> <link rel='stylesheet' id='dashicons-css' href='http://localhost/wordpress_5_4_2_try3/wp-includes/css/dashicons.min.css?ver=5.4.6' media='all' /> <link rel='stylesheet' id='buttons-css' href='http://localhost/wordpress_5_4_2_try3/wp-includes/css/buttons.min.css?ver=5.4.6' media='all' /> <link rel='stylesheet' id='forms-css' href='http://localhost/wordpress_5_4_2_try3/wp-admin/css/forms.min.css?ver=5.4.6' media='all' /> <link rel='stylesheet' id='l10n-css' href='http://localhost/wordpress_5_4_2_try3/wp-admin/css/l10n.min.css?ver=5.4.6' media='all' /> <link rel='stylesheet' id='login-css' href='http://localhost/wordpress_5_4_2_try3/wp-admin/css/login.min.css?ver=5.4.6' media='all' /> <meta name='robots' content='noindex,noarchive' /> <meta name='referrer' content='strict-origin-when-cross-origin' /> <meta name="viewport" content="width=device-width" /> </head> <body class="login no-js login-action-rp wp-core-ui locale-en-us"> <script type="text/javascript"> document.body.className = document.body.className.replace('no-js','js'); </script> <div id="login"> <h1><a href="https://wordpress.org/">Powered by WordPress</a></h1> <p class="message reset-pass">Enter your new password below.</p> <form name="resetpassform" id="resetpassform" action="http://localhost/wordpress_5_4_2_try3/wp-login.php?action=resetpass" method="post" autocomplete="off"> <input type="hidden" id="user_login" value="user_name " autocomplete="off" /> <div class="user-pass1-wrap"> <p> <label for="pass1">New password</label> </p> <div class="wp-pwd"> <input type="password" data-reveal="1" data-pw="t)&NlDW$C7wgG^20" name="pass1" id="pass1" class="input password-input" size="24" value="" autocomplete="off" aria-describedby="pass-strength-result" /> <button type="button" class="button button-secondary wp-hide-pw hide-if-no-js" data-toggle="0" aria-label="Hide password"> <span class="dashicons dashicons-hidden" aria-hidden="true"></span> </button> <div id="pass-strength-result" class="hide-if-no-js" aria-live="polite">Strength indicator</div> </div> <div class="pw-weak"> <input type="checkbox" name="pw_weak" id="pw-weak" class="pw-checkbox" /> <label for="pw-weak">Confirm use of weak password</label> </div> </div> <p class="user-pass2-wrap"> <label for="pass2">Confirm new password</label> <input type="password" name="pass2" id="pass2" class="input" size="20" value="" autocomplete="off" /> </p> <p class="description indicator-hint">Hint: The password should be at least twelve characters long. To make it stronger,use upper and lower case letters,numbers,and symbols like ! " ? $ % ^ & ).</p> <br class="clear" /> <input type="hidden" name="rp_key" value="theKey" /> <p class="submit"> <input type="submit" name="wp-submit" id="wp-submit" class="button button-primary button-large" value="Reset Password" /> </p> </form> <p id="nav"> <a href="http://localhost/wordpress_5_4_2_try3/wp-login.php">Log in</a> | <a href="http://localhost/wordpress_5_4_2_try3/wp-login.php?action=register">Register</a> </p> <p id="backtoblog"><a href="http://localhost/wordpress_5_4_2_try3/"> ← Back to wordPrSite3 </a></p> </div> <script type="text/javascript"> try{document.getElementById('user_pass').focus();}catch(e){} if(typeof wpOnload=='function')wpOnload(); </script> <script> var pwsL10n = {"unknown":"Password strength unknown","short":"Very weak","bad":"Weak","good":"Medium","strong":"Strong","mismatch":"Mismatch"}; </script> <script src='http://localhost/wordpress_5_4_2_try3/wp-admin/js/password-strength-meter.min.js?ver=5.4.6'></script> <script src='http://localhost/wordpress_5_4_2_try3/wp-includes/js/underscore.min.js?ver=1.8.3'></script> <script> var _wpUtilSettings = {"ajax":{"url":"\/wordpress_5_4_2_try3\/wp-admin\/admin-ajax.php"}}; </script> <script src='http://localhost/wordpress_5_4_2_try3/wp-includes/js/wp-util.min.js?ver=5.4.6'></script> <script> var userProfileL10n = {"warn":"Your new password has not been saved.","warnWeak":"Confirm use of weak password","show":"Show","hide":"Hide","cancel":"Cancel","ariaShow":"Show password","ariaHide":"Hide password"}; </script> <script src='http://localhost/wordpress_5_4_2_try3/wp-admin/js/user-profile.min.js?ver=5.4.6'></script> <script> /(trident|msie)/i.test(navigator.userAgent)&&document.getElementById&&window.addEventListener&&window.addEventListener("hashchange",function(){var t,e=location.hash.substring(1);/^[A-z0-9_-]+$/.test(e)&&(t=document.getElementById(e))&&(/^(?:a|select|input|button|textarea)$/i.test(t.tagName)||(t.tabIndex=-1),t.focus())},!1); </script> <div class="clear"></div> </body> </html>
-
在使用 postman 并仅发出 post 请求后,我发现它没有将我重定向到该页面,但预览看起来像这样: Preview from postman
因此,在研究了 r2.text 之后,我更改了代码并再次尝试使用以下信息:
info = {'pass1':'a_password#38','pass2':'a_password#38'}
不幸的是,结果是一样的,我对到底发生了什么感到非常困惑。
所以,我的问题是(最重要的是第三个问题):
- 为什么一个简单的 post 请求不足以提交新密码(或密码和密码确认)?
- 为什么当我从我的浏览器尝试它时,我被重定向到一个包含 1 个字段的页面(我在第一个图片链接中显示的那个),而邮递员和从一个简单的 get 请求返回到 http 的代码://localhost/wordpress_5_4_2_try3/wp-login.php?action=rp&key=theKey&login=user_name 表示需要 2 个字段?
- 您知道如何通过请求或其他工具/库来表达自己的意思吗?我使用 Python 请求,但当然也欢迎使用其他语言。我的目标是不使用实际打开浏览器的工具,这比我愿意提供的要花费大量时间和资源(我想并行发出一些请求并测量性能)。
感谢任何帮助!谢谢。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。