Posted 10 November 2016 - 12:47 AM
Hi guys
so i have been trying to make a User create based on the one on this page:
How to Securely Store Passwords by computech
http://www.computerc...768#entry260768
as you can see i have posted my code there and awaited for some help but no response.
Cant seem to be able to get it to write users to the file and debug other bits. And now stuck. Thanks for your help if you can in advance.
code:-
so i have been trying to make a User create based on the one on this page:
How to Securely Store Passwords by computech
http://www.computerc...768#entry260768
as you can see i have posted my code there and awaited for some help but no response.
Cant seem to be able to get it to write users to the file and debug other bits. And now stuck. Thanks for your help if you can in advance.
code:-
Spoiler
--A user Maker. This will Check a password file for a user if not present it will make the user and salt their user password.
--Api's to load
os.loadAPI("sha")
--VARIABLES
--Global
--none
--local
local fileName = "PSW" --name of password file.
--END OF VARIABLES
--FUNCTIONS
--Global
function setScreen()-- works, This clears the screen and positions us in the top left of the terminal. This needs to be a global function.
term.clear() -- set screen up
term.setCursorPos(1,1)
term.setCursorBlink(true)
print("hello") --testing text
end--close function
--local
local function createFile ( )--This creates The password file if it doesnt exsit.
setScreen()
if not fs.exists(fileName) then --Create a password file
write(": File ", fileName ," Not Found")
write(": Creating File ",fileName)
local f = fs.open(fileName, "w") --This creates the file in a writable state as a veriableM
f.write(textutils.serialize({ })) --This puts the text we want in the file
f.close() --This closes the file
write (": Created File ", fileName )
else
write(": File ",fileName," Found")
end
end
local function readFile()
local f = fs.open(fileName,"r")
local usrs = textutils.unserialize(f.readAll())
f.close()-- we have now checked the file to see whos in it read and stored all the names and passwords in memorry.
print(": ",fileName," Read")
end
local function userName()
setScreen()
readFile()
write("UserName :: ") -- ask for username
local u = read()--read the user password response, comit to variable u
if not usrs[u] then -- we reconise its a new user and carry on and create the password
write("password :: ") --ask for user password
local p = read()--read the user password response, comit to variable p
local salt = math.random(1,10000000000000)*math.random(1,10000000000000)
*math.random (1,10000000000000) -- massive over kill to get a really big random number i know
usrs[u] = {
pwd = sha.sha256( p .. salt ),
salt = salt,
}
local f = fs.open(passPath, "w")
f.write( textutils.serialize( usrs ) )
f.close()
else
write("UserName already taken")
os.sleep(2)
userName()
end
end
--END OF FUNCTIONS
--CODE
createFile(fileName) --call function and pass file name PSW into it.
os.sleep(2)
readFile(fileName) -- Read the File PSW
os.sleep(2)
userName()
-- END OF CODE
--[[
This is my variation of CompuTech's user maker on page (How to Securely Store Passwords).
This can be found at http://www.computercraft.info/forums2/index.php?/topic/27496-how-to-securely-store-passwords/page__p__260768#entry260768
os.loadAPI("sha")
write("username :: ")
local u = read()
write("password :: ")
local p = read()
--Again, change passPath here
local passPath = "passwords"
local f = fs.open(passPath,"r")
local usrs = textutils.unserialize(f.readAll())
f.close()
if not usrs[u] then
local salt = os.time()
usrs[u] = {
pwd = sha.sha256( p .. salt ),
salt = salt,
}
local f = fs.open(passPath, "w")
f.write( textutils.serialize( usrs ) )
f.close()
end
--]]
Edited on 19 November 2016 - 10:34 PM