Add 2FA to your Roblox games

This is a module for generating and verifying time-based one-time passwords (TOTP) in Roblox games. Fully compatible with standard authenticator apps like Google Authenticator, Authy, and Microsoft Authenticator.

Get it here
https://create.roblox.com/store/asset/103769621801747/TOTP

Demo

Usage

⚠️ Place the TOTP module script in ServerScriptService and wait until it parents itself to ReplicatedStorage before using it.

Use this code to validate TOTP codes on the server.

-- Server
local ReplicatedStorage = game:GetService('ReplicatedStorage')
local TOTP = require(ReplicatedStorage:WaitForChild('TOTP'))

ReplicatedStorage.AcceptTrade.OnServerInvoke = function(Player: Player, TradeID: string, TOTPCode: string)

	-- Validate TOTP
	if (not TOTP:Validate(Player, TOTPCode)) then
		return false, 'Invalid TOTP'
	end

	-- Process trade
	-- TradeModule:ProcessTrade(TradeID)

	return true
end

Use this code to generate a new QR code for a player to scan. Once the player scans the QR code and confirms the 6 digit TOTP, the QR code will never be exposed to the player again.

-- Client
local ReplicatedStorage = game:GetService('ReplicatedStorage')
local TOTP = require(ReplicatedStorage:WaitForChild('TOTP'))

local QRFrame = script.Parent.QR
local ResetButton = script.Parent.Reset
local IsResetBusy = false

ResetButton.Activated:Connect(function()
	if (IsResetBusy) then return end
	IsResetBusy = true
	
	-- Attempt reset
	local Success, Response = TOTP:Reset()
	
	if (Success) then
		
		-- Show new QR code
		local URI = Response

		TOTP:GenerateQR(URI, QRFrame)
	else
		warn(`Failed to reset TOTP, {Response}`)
	end
	
	IsResetBusy = false
end)

Use this code to show the built-in UI

-- Client
local ReplicatedStorage = game:GetService('ReplicatedStorage')
local TOTP = require(ReplicatedStorage:WaitForChild('TOTP'))

local TOTPButton = script.Parent.TOTP

TOTPButton.Activated:Connect(function()
	TOTP:ToggleGenerator()
end)
13 Likes

QR codes are links, and you’re not allowed to show links to users at all. This is breaking the ToS!

Also see PolicyService. No external references are allowed anymore.

https://create.roblox.com/docs/reference/engine/classes/PolicyService#GetPolicyInfoForPlayerAsync

11 Likes

QR codes are not links, they are QR codes. Also this does not show any external references to the user.

2 Likes

Based on my warning from a barcode on an image, this is probably going to get banned for off-site links. And no it does not matter if it’s fake since I used a fake barcode and they rejected my warning appeal.

1 Like

QR codes are just matrix of bits, which can represent pretty much any datatype, number, string, url, even a full on game, if you compress it enough (there is youtube video about writing game source code so small that it fits inside biggest QR code standard).

Bits and binary overall is not made to be human readable, thus humans cannot say if QR code is a url, number, or anything else. That would allow inserting malicious content into QR code, such as a link and well, doing malicious things to end users device.

1 Like

Just as I figured would happen.


Also does it make the QR Code via frames and not images?

1 Like

?? its not a link at all its a key

1 Like

Right, not all QR codes are links. But this one is! It’s a URI that starts with otpauth://totp/. There’s also a pretty well known protocol called https:// and both of these are the beginning of links, hence why the model got taken down.

1 Like

otpauth:// is not a link. If you scan the QR code with your phone it does not open any website or app or link you to anything.

3 Likes

whats the use case for this feature?

1 Like

Admins for games could be forced to register 2FA so that if their account gets stolen from them the bad actor can’t do anything within the experience itself so long as they haven’t got site-wide edit access.

2 Likes

they can still edit datastores with the console

1 Like

If the admins of your game have edit game permission, then this is not your only problem.

1 Like

Erm actually it is not. Not all QR Codes are links, which in this case, TOTP codes are not links, they are just strings of text.

1 Like

That’s not how it works. The codes aren’t stored in datastore.

1 Like

Congratulations, you have made a rather unique project. I won’t comment on the TOS aspect of this since it doesn’t concern me, neither do I know the answer without scanning documents. Since you did the work, I’m sure you researched policy guidelines beforehand.

I wouldn’t say this would be that useful for games, however I think it’s a cool project to showcase. Not every resource needs to be widely used; I enjoy the art of unique creations. Great job!

1 Like

Gonna pretend I didn’t just read that.

2 Likes

what are they gonna do without it
type ;ban manually or something in HD admin

1 Like

i just ctrl F the thread and nobody said anything about getting codes from a datastore
take your meds

1 Like

Love this, could be used for our trading game, but I really want to see an admin comment on this


and its taken down

1 Like