在保持多步骤流程一致性时我需要用到token(比如找回密码):
步骤1,用户提交要找回密码的用户名和验证码,我生成token1,返回页面中包含这个token1
步骤2,用户提交他收到的短信验证码和token1,我根据token1来识别是哪个用户,短信验证码是否正确,token是否过期,这个token的使用场景是否正确,如果都有效,我生成一个token2,返回页面包含这个token2
步骤3,用户提交他的新密码和token2,我根据token2来找出是哪个用户,最后重置那个用户的密码
这里的token都有时效性,我存在mysql里,每天都要跑cron job来删除过期的token,这样不太好吧,我应该怎么存token?或者有更好的办法?
回复内容:
在保持多步骤流程一致性时我需要用到token(比如找回密码):
步骤1,用户提交要找回密码的用户名和验证码,我生成token1,返回页面中包含这个token1
步骤2,用户提交他收到的短信验证码和token1,我根据token1来识别是哪个用户,短信验证码是否正确,token是否过期,这个token的使用场景是否正确,如果都有效,我生成一个token2,返回页面包含这个token2
步骤3,用户提交他的新密码和token2,我根据token2来找出是哪个用户,最后重置那个用户的密码
这里的token都有时效性,我存在mysql里,每天都要跑cron job来删除过期的token,这样不太好吧,我应该怎么存token?或者有更好的办法?
token可以使用 md5(username+userid+timestamp)_timestamp,这种格式的token基本上不会重复了,同时尾部的timestample也能用于过期检测。
对于一个用户来说通常一个token就够了,当你生成第二个token的时候第一个已经失效了,所以可以直接update掉,这样每个用户最多有一个token就不需要考虑删除的问题了,当然在token被验证有效地时候应该把数据库中的token set null,防止同一个token被二次验证。
token不需要存储的,你可以使用AES的可逆向加/解密算法对数据进行加密,如aes.ecode(userId+time+info+key(密钥)),生成token后把这个串传回给客户端,不需要保存,等下次他传回给你的时候你只需要aes.decode(token)解密一下就可以获得这里面的用户信息与当前登陆的用户信息对比一下就行了
或者不用储存token,有效性信息就放在token里,你看看这个json web token
token不用存mysql吧,存内存就好了。
一个线程轮训删除过期的token数据。
当然你会说宕机了,内存数据就没了,但是基于找回密码的操作不常有,这个数据不会太多,而时效性一般不会太长,如果真遇到宕机,宕机了用户也无法访问了啊,故这个token就废弃也无所谓,让用户重新提交找回操作。
可以存memcahe或redis里,缓存设定时间过期。
我一般直接存session
token 我是用md5 用户名加 现有密码生成....
然后记录下时间
存redis,设置过期时间是最方便的
token类似于单个web工程中使用的session,保存起来便于查看访问日志,不保存也可以,但每个模块和功能的操作日志最好记录一下,以便后期运营和维护使用。

What’s still popular is the ease of use, flexibility and a strong ecosystem. 1) Ease of use and simple syntax make it the first choice for beginners. 2) Closely integrated with web development, excellent interaction with HTTP requests and database. 3) The huge ecosystem provides a wealth of tools and libraries. 4) Active community and open source nature adapts them to new needs and technology trends.

PHP and Python are both high-level programming languages that are widely used in web development, data processing and automation tasks. 1.PHP is often used to build dynamic websites and content management systems, while Python is often used to build web frameworks and data science. 2.PHP uses echo to output content, Python uses print. 3. Both support object-oriented programming, but the syntax and keywords are different. 4. PHP supports weak type conversion, while Python is more stringent. 5. PHP performance optimization includes using OPcache and asynchronous programming, while Python uses cProfile and asynchronous programming.

PHP is mainly procedural programming, but also supports object-oriented programming (OOP); Python supports a variety of paradigms, including OOP, functional and procedural programming. PHP is suitable for web development, and Python is suitable for a variety of applications such as data analysis and machine learning.

PHP originated in 1994 and was developed by RasmusLerdorf. It was originally used to track website visitors and gradually evolved into a server-side scripting language and was widely used in web development. Python was developed by Guidovan Rossum in the late 1980s and was first released in 1991. It emphasizes code readability and simplicity, and is suitable for scientific computing, data analysis and other fields.

PHP is suitable for web development and rapid prototyping, and Python is suitable for data science and machine learning. 1.PHP is used for dynamic web development, with simple syntax and suitable for rapid development. 2. Python has concise syntax, is suitable for multiple fields, and has a strong library ecosystem.

PHP remains important in the modernization process because it supports a large number of websites and applications and adapts to development needs through frameworks. 1.PHP7 improves performance and introduces new features. 2. Modern frameworks such as Laravel, Symfony and CodeIgniter simplify development and improve code quality. 3. Performance optimization and best practices further improve application efficiency.

PHPhassignificantlyimpactedwebdevelopmentandextendsbeyondit.1)ItpowersmajorplatformslikeWordPressandexcelsindatabaseinteractions.2)PHP'sadaptabilityallowsittoscaleforlargeapplicationsusingframeworkslikeLaravel.3)Beyondweb,PHPisusedincommand-linescrip

PHP type prompts to improve code quality and readability. 1) Scalar type tips: Since PHP7.0, basic data types are allowed to be specified in function parameters, such as int, float, etc. 2) Return type prompt: Ensure the consistency of the function return value type. 3) Union type prompt: Since PHP8.0, multiple types are allowed to be specified in function parameters or return values. 4) Nullable type prompt: Allows to include null values and handle functions that may return null values.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Atom editor mac version download
The most popular open source editor

SublimeText3 Linux new version
SublimeText3 Linux latest version

SublimeText3 Mac version
God-level code editing software (SublimeText3)

SublimeText3 English version
Recommended: Win version, supports code prompts!

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.