Junior — Middle
Where should data about the first stage be stored when creating a temporary code for SMS confirmation?
sobes.tech AI
Answer from AI
Data about the first stage when creating a temporary code for SMS confirmation (for example, the code itself, creation time, user identifier) should be stored in a secure and temporary storage on the server. Typically, this is done using:
- Database — creating a table to store confirmation codes with fields: code, user, creation time, expiration time.
- Cache system (Redis, Memcached) — for quick access and automatic deletion after expiration.
It is important that the data is linked to a specific user and has a limited lifespan (TTL), so that the code cannot be reused or after the expiration time.
Example using Redis in C#:
// Save the code with a TTL of 5 minutes
var redis = ConnectionMultiplexer.Connect("localhost");
var db = redis.GetDatabase();
string key = $"sms_code:{userId}";
string code = GenerateCode();
db.StringSet(key, code, TimeSpan.FromMinutes(5));
Thus, data about the first stage is stored on the server in a controlled and temporary storage, not on the client.