Like many big popular websites such as YouTube, Facebook, and ROBLOX, they don't store passwords normally as text(That would be a terrible idea). When you send passwords they go through and become encrypted. That way if there is an attacker or leaks, you don't see: "03_23_2001" as a password. They encrypt it in a semi-random fashion. So the outcome becomes like so: 4wh2sifee2sh45d3. When you send your password to the server, they don't send your password like it was when you typed it in, they save the encrypted version and they encrypt your password in the same encryption method they used when you signed up. That's why websites don't mind if you don't use correct capitalisation when typing in your username, but when typing in passwords, each letter is different and each capital letter becomes a different letter than a lowercase one. This makes it easy to encrypt a password, but not steal passwords. Think of an encrypter as a math equation:
45*112 = 5040
--45*112 is the password you type in, and 5040 is like the number that comes out after encryption.
5040
--Now let's say you hacked into a site and you find 5040. How can you trace it back to what the user originally typed in when there are so many other possibilities!
1*5040, 5040, 5040+0, 5030+10, 5031+9, 6000-60, 420*12...
--The list goes on and on, there are a bunch of possibilities! And you can't just type in 5040 because that will also get encrypted!
So this is what makes password systems so secured. I'm trying to recreate this in ROBLOX but it's more difficult than it seems.
It's really easy to do this with numbers: Just put the numbers through a function and keep repeating it a random number of times, then use DataStores to save that random number and use that number the next time they sign in.
game:GetService("Players").PlayerAdded:connect(function(plyr)
local num = math.random(1,100)
local ds = game:GetService("DataStoresService")
local rnum = ds:GetDataStore("rnum")
local pswrd = ds:GetDataStore("PasswordArchive")
if rnum:GetAsync(plyr.userId) == nil then
rnum:SetAsync(plyr.userId, num)
else
num = rnum:GetAsync(plyr.userId)
end
function encrypt(password)
local var = password
for i = 1,num do
var = var*12/32+52^3+i
end
return var
end
if not pswrd:GetAsync(plyr.userId) then
pswrd:SetAsync(plyr.userId, encrypt(213))
end
end)
This would work, but what if the player is using letters in their password? And what if 2 people had completely different passwords, but through pure chance, they got the same encryption?(That one is an easy fix)
Any help is appreciated. Thanks!
######Sources YouTube Doesn't Know Your Password - Tom Scott, 5040 and other Anti-Prime Numbers - Numberphile, How NOT to Store Passwords! - Computerphile
####Ideas I had that might work
- Turning passwords into binary then using my first encryption method(Too lengthy and inconvenient)
- Change each character into another(Too easy to crack)
- Use the Enigma Machine method(Too complicated and has flaws)
- Hash-Salting(would need to transfer other coding languages into Lua)

2 comments
He could send requests to a web server which would then do the encryption for him (much more secure than using pure Lua).
Yes, but I'm asking for the best way to code it, because all other ways are too inconvenient or too easy to crack.