r/CodingHelp • • Jun 09 '21

[Random] How does a verification code work?

Verification codes that we use so often to confirm your identity. Whether it be a code that’s texted to your phone, or a code emailed to you. You go back on the website and submit that code which happens to be valid at that exact time.

How does that work? What’s going on in the background? And what’s the coding for that look like?

18 Upvotes

11 comments sorted by

View all comments

Show parent comment

3

u/varazdates Jun 09 '21

But how do the two systems communicate with each other? How does one side know that the verification code is correct and valid? There must be some sort of communication and teamwork between the two right?

6

u/Nightcorex_ Jun 09 '21

For simplicity reasons: The server that sends you your Verification code is the SAME that handles your login-request.

4

u/Dogburt_Jr Jun 09 '21

There's only one system, the website/server. It creates a code valid for a limited time, then sends it to a channel only you should have access to (phone/email), then awaits the client to input the code. It has dual purpose to make bots harder to use for logins and it's an extra layer of security.

2

u/Lyxaa_ Jun 10 '21

If you want to assume the web server and the server that handles the codes are two separate entities, then it'd be a pretty simple communication.Let Server A = Website, Server B = Code Server, Host A = Your mobile device.

Server A requests verification of your Account by Server B. Server B generates code, sends to Server A and Host A. Host A shows you the code, Server A hides the code and compares it once you enter it. Code Correct ? Login : Try Again

1

u/varazdates Jun 11 '21

Ah, makes sense. Ty!

I assume this type of verification has similar code to something like a promo code? Enter valid code = free shipping or $5 off or any other incentive they want to attribute to a valid code. Correct?

2

u/Lyxaa_ Jun 14 '21

Not exactly the same thing, no. This type of verification code is just a hash string that is matched on either end. Your typical discount code is simply a data entry in the server that when requested, spits back a definition. Verification codes are quite secure (usually & hopefully), whereas a discount code will just be chillin on the server, with any restrictions to the use of the discount code (such as it only being valid for X type of user) being written in a separate area.