search
HomeBackend DevelopmentPHP Tutorial 怎么生成“密码重置”那种“一次性链接”

如何生成“密码重置”那种“一次性链接”
RT. 
就像一些网站用来给忘记密码的用户,提供的密码重置的链接。

发到用户注册邮箱里的那种,只能触发一次,用过一次以后就不能用了。

有时候还有时间限制,比如24小时内链接有效之类的。

谁知道 这个用 PHP 如何实现呢。  

谢谢啦

------解决方案--------------------
时间轴控制。先生成连接,记录生成时间,然后设置死亡时间。超过24小时或者点击过一次后就over
------解决方案--------------------
根据时间戳什么的生成可逆加密串 取得后再进行还原验证 验证时间是否超时就可以了.
------解决方案--------------------
要实现一次性的话那就得把加密串记录下来了,每次收到连接请求 到记录里面查询一下
------解决方案--------------------
“一次性”???
很简单,你只需查询一下表,在表中就通过,否则就拒绝

表中只需一个字段 char(32) 设为主键
只存放需要验证内容的 MD5 值
操作也很简单,执行 delete from tbl_name where key='值'
如果 mysql_affected_rows 返回 0 就表示未通过

这个方案可以验证任何“一次性”,只要你取得要验证对象的MD5。无需顾忌验证对象的真实内容
------解决方案--------------------
扯淡.

点重置密码,你就给数据库插一行,有自增ID做KEY,并且有用户名,是否完成验证,创建日期TIME_STAMP,唯一标示符md5. (为了数据库安全性,生成一个MD5值作标识发给用户,md5(id . username . time))。
然后发个URL在邮件里:xxxx.com?id=md5即可。

用户访问这个url的时候从数据库里找该md5,标记完成即可。
------解决方案--------------------
=。= 还用表? 这种数据记录下来貌似是给dba找麻烦呀...

随便用 username + unixtimestamp + 一段key 然后对某几位进行一下哈希不就行了?....

验证超时的时候,提取出unixtimestamp字段,就可以随意做时间限制了...
------解决方案--------------------
我说说我的思路。其实很简单
因为SESSION是有生命期的,SESSION过期同时链接自动过期即可。
思路:
确定用户身份后。利用session ID+用户名 生成一个唯一的标识

PHP code

$_SESSION['FORGET_CODE']=md5(session_id() . 'XXX');        //XXX是要重置密码的用户名
/*生成的链接如下*/
$href="http://www.domain.com/forget.php?code={$_SESSION['FORGET_CODE']}";
<br><font color="#e78608">------解决方案--------------------</font><br>1,可以把用户的申请时间记录到数据库中<br>2,使用能解密的算法,把时间也做为数据加密,discuz有这种方法。 <div class="clear">
                 
              
              
        
            </div>
Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
PHP's Purpose: Building Dynamic WebsitesPHP's Purpose: Building Dynamic WebsitesApr 15, 2025 am 12:18 AM

PHP is used to build dynamic websites, and its core functions include: 1. Generate dynamic content and generate web pages in real time by connecting with the database; 2. Process user interaction and form submissions, verify inputs and respond to operations; 3. Manage sessions and user authentication to provide a personalized experience; 4. Optimize performance and follow best practices to improve website efficiency and security.

PHP: Handling Databases and Server-Side LogicPHP: Handling Databases and Server-Side LogicApr 15, 2025 am 12:15 AM

PHP uses MySQLi and PDO extensions to interact in database operations and server-side logic processing, and processes server-side logic through functions such as session management. 1) Use MySQLi or PDO to connect to the database and execute SQL queries. 2) Handle HTTP requests and user status through session management and other functions. 3) Use transactions to ensure the atomicity of database operations. 4) Prevent SQL injection, use exception handling and closing connections for debugging. 5) Optimize performance through indexing and cache, write highly readable code and perform error handling.

How do you prevent SQL Injection in PHP? (Prepared statements, PDO)How do you prevent SQL Injection in PHP? (Prepared statements, PDO)Apr 15, 2025 am 12:15 AM

Using preprocessing statements and PDO in PHP can effectively prevent SQL injection attacks. 1) Use PDO to connect to the database and set the error mode. 2) Create preprocessing statements through the prepare method and pass data using placeholders and execute methods. 3) Process query results and ensure the security and performance of the code.

PHP and Python: Code Examples and ComparisonPHP and Python: Code Examples and ComparisonApr 15, 2025 am 12:07 AM

PHP and Python have their own advantages and disadvantages, and the choice depends on project needs and personal preferences. 1.PHP is suitable for rapid development and maintenance of large-scale web applications. 2. Python dominates the field of data science and machine learning.

PHP in Action: Real-World Examples and ApplicationsPHP in Action: Real-World Examples and ApplicationsApr 14, 2025 am 12:19 AM

PHP is widely used in e-commerce, content management systems and API development. 1) E-commerce: used for shopping cart function and payment processing. 2) Content management system: used for dynamic content generation and user management. 3) API development: used for RESTful API development and API security. Through performance optimization and best practices, the efficiency and maintainability of PHP applications are improved.

PHP: Creating Interactive Web Content with EasePHP: Creating Interactive Web Content with EaseApr 14, 2025 am 12:15 AM

PHP makes it easy to create interactive web content. 1) Dynamically generate content by embedding HTML and display it in real time based on user input or database data. 2) Process form submission and generate dynamic output to ensure that htmlspecialchars is used to prevent XSS. 3) Use MySQL to create a user registration system, and use password_hash and preprocessing statements to enhance security. Mastering these techniques will improve the efficiency of web development.

PHP and Python: Comparing Two Popular Programming LanguagesPHP and Python: Comparing Two Popular Programming LanguagesApr 14, 2025 am 12:13 AM

PHP and Python each have their own advantages, and choose according to project requirements. 1.PHP is suitable for web development, especially for rapid development and maintenance of websites. 2. Python is suitable for data science, machine learning and artificial intelligence, with concise syntax and suitable for beginners.

The Enduring Relevance of PHP: Is It Still Alive?The Enduring Relevance of PHP: Is It Still Alive?Apr 14, 2025 am 12:12 AM

PHP is still dynamic and still occupies an important position in the field of modern programming. 1) PHP's simplicity and powerful community support make it widely used in web development; 2) Its flexibility and stability make it outstanding in handling web forms, database operations and file processing; 3) PHP is constantly evolving and optimizing, suitable for beginners and experienced developers.

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
1 months agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

Atom editor mac version download

Atom editor mac version download

The most popular open source editor