Hi Guys thank you for your help i have got it to work now and you can find the code at:
http://pastebin.com/Vr8tYMP8
http://www.computerc...ng-and-salting/
- ComputerCraft | Programmable Computers for Minecraft
- → lebalusch's Content
lebalusch's Content
There have been 6 items by lebalusch (Search limited from 10-February 22)
#262022 Password File Creator (hashing and Salting)
Posted by
lebalusch
on 19 November 2016 - 11:09 PM
in
Programs
Hi Guys,
So Here is a basic Password File Creator.
http://pastebin.com/Vr8tYMP8
-- Program: MkUser
-- Version: 0.1
-- Author: LebaLusch
-- Created: 19/11/16 -uk date style
-- Use: This will Check a password file (if not Present it will create it) for a user Name if not present it will store the name and Password. The password will be Hashed and Salted.
-- Features i want to add:
Removal of users.
Auto Add a Admin user.
This is my variation of CompuTech's user maker Whos code can be found at page (How to Securely Store Passwords).
This can be found at http://www.computerc...768#entry260768
Change the fileName for your password file on line 56 (local fileName = "AnythingYouWant")
CODE
So Here is a basic Password File Creator.
http://pastebin.com/Vr8tYMP8
-- Program: MkUser
-- Version: 0.1
-- Author: LebaLusch
-- Created: 19/11/16 -uk date style
-- Use: This will Check a password file (if not Present it will create it) for a user Name if not present it will store the name and Password. The password will be Hashed and Salted.
-- Features i want to add:
Removal of users.
Auto Add a Admin user.
This is my variation of CompuTech's user maker Whos code can be found at page (How to Securely Store Passwords).
This can be found at http://www.computerc...768#entry260768
Change the fileName for your password file on line 56 (local fileName = "AnythingYouWant")
CODE
Spoiler
--[[
-- Program: MkUser
-- Version: 0.1
-- Author: LebaLusch
-- Created: 19/11/16 -uk date style
-- Dependencies:
api=sha sha256.lua made by MaHuJa https://github.com/MaHuJa/CC-scripts/blob/master/sha256.lua (From http://pastebin.com/gsFrNjbt)
-- Use: This will Check a password file (if not Present it will create it) for a user Name if not present it will store the name and Password. The password will be Hashed and Salted.
-- Features i want to add:
Removal of users.
Auto Add a Admin user.
-- Credits:
All those that have Created and contributed to making Lua what it is today.
This is my variation of CompuTech's user maker Whos code can be found at 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
--Links:
http://www.lua.org/
http://www.computercraft.info/
http://www.computercraft.info/forum2
http://www.minecraft.net
]]
--[[Licence]]
--[[
THE SOFTWARE IS PROVIDED "AS IS",
WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED,
INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
YOU MAY NOT USE ANY PART OF THIS SOFTWARE UNLESS YOU CREDIT THE AUTHOR FOUND ABOVE IN YOUR HEADER.
YOU MAY NOT USE ANY PART OF THIS SOFTWARE IN A COMERCIAL PRODUCT FOR PROFIT,
OR SOFTWARE THAT DOES NOT ALLOW THE USER FULL ACCESS TO THE CODE.
]]
--Api's to load
os.loadAPI("sha")
local fileName = "PSW" --name of password file.
--FUNCTIONS
local 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)
end--close function
local function createFile ( )--This creates The password file if it doesnt exsit.
setScreen()
write(">Creating User-\n\n")
if not fs.exists(fileName) then --Create a password file
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
else
--nothing
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.
end
function userName()
setScreen()
write(">Creating User-\n\n")
write(">User Name: ") -- ask for username
local u = read()--read the user name response, comit to variable u
local f = fs.open(fileName,"r")
local usrs = textutils.unserialize(f.readAll())
f.close()
if not usrs [u] then -- we reconise its a new user and carry on and create the password .usrs
write(">Password: ") --ask for user password
p = read("*")--read the user password response, comit to variable p
write(">Password: ") --ask for user password again and check them agains each other
local chkP = read("*")
if p == chkP then
write("\n>Passwords Match\n")
os.sleep(3)
else
write(">Passwords Do Not Match\n")
os.sleep(3)
userName()
end
local salt = os.time() *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(fileName, "w")
f.write( textutils.serialize( usrs ) )
f.close()
write(">User created\n")
os.sleep(3)
setScreen()
else
setScreen()
write(">User Name already taken\n")
write(">Please Try again")
os.sleep(3)
userName()
end
end
--END OF FUNCTIONS
--CODE
createFile(fileName) --call function and pass file name PSW into it.
readFile(fileName) -- Read the File PSW
userName() -- take the user name and check it and also check the password with each other.
write("\n\n--program finished--\n") --place card holder
-- END OF CODE
#261633 [solved] Bug in Code, Please Help (user creation)
Posted by
lebalusch
on 10 November 2016 - 12:47 AM
in
Ask a Pro
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
--]]
#260768 How to Securely Store Passwords
Posted by
lebalusch
on 18 October 2016 - 11:06 PM
in
Tutorials
i got it working again and now its stopped.
i would like in the end to hash the user names as well so its totally unreadable whos hash is whos.
I have done a first version of mine you can find it here.
http://www.computerc...ng-and-salting/
http://pastebin.com/Vr8tYMP8
Spoiler
os.loadAPI("sha")
--functions--
local passPath = "PSW" --Change this if you want a different password file
local function checkFile(passPath)
if not fs.exists(passPath) then --Create a password file
local f = fs.open(passPath, "w")
f.write(textutils.serialize({ }))
f.close()
term.write("No Password file found, Password file created")
else
term.write("Password file read")
end
end
--code--
checkFile(passPath)--run function above
write("username :: ")
local u = read()
write("password :: ")
local p = read()
--Again, change passPath here
local passPath = "PSW"
local f = fs.open(passPath,"r")
local usrs = textutils.unserialize(f.readAll())
f.close()
if not usrs[u] then
local salt = math.random(1,10000000000000)*math.random(1,10000000000000)*math.random(1,10000000000000)
usrs[u] = {
pwd = sha.sha256( p .. salt ),
salt = salt,
}
local f = fs.open(passPath, "w")
f.write( textutils.serialize( usrs ) )
f.close()
end
i would like in the end to hash the user names as well so its totally unreadable whos hash is whos.
I have done a first version of mine you can find it here.
http://www.computerc...ng-and-salting/
http://pastebin.com/Vr8tYMP8
#260752 How to Securely Store Passwords
Posted by
lebalusch
on 17 October 2016 - 10:06 PM
in
Tutorials
Hi guys its happening again.
the User creation script seems to not find the passwords i guess as it keeps crashing when it gets to this line.
line15
if not usrs[u] then
giving a MkUser:15: attempt to index ? (a nil value)
any ideas? was running fine all night then with a reset of the server its back to not working right.
the User creation script seems to not find the passwords i guess as it keeps crashing when it gets to this line.
line15
if not usrs[u] then
giving a MkUser:15: attempt to index ? (a nil value)
any ideas? was running fine all night then with a reset of the server its back to not working right.
#260738 How to Securely Store Passwords
Posted by
lebalusch
on 16 October 2016 - 10:34 PM
in
Tutorials
SOLVED IGNORE
Hi Im finding the User creation script to not be working for me correctly. I got the "sha" file and also the "passwords" file at the normal root (new pc and just edit off the main screen) So guessing i has to change Ln 7 to "passPath = "/passwords"
so i run the userMaker. enter the user name, then password and then it crashes. "UserMaker:11:attept to index ? (a nil value)
any ideas where i have got it wrong or if these scripts above are not working right.
cheers guys
Hi Im finding the User creation script to not be working for me correctly. I got the "sha" file and also the "passwords" file at the normal root (new pc and just edit off the main screen) So guessing i has to change Ln 7 to "passPath = "/passwords"
so i run the userMaker. enter the user name, then password and then it crashes. "UserMaker:11:attept to index ? (a nil value)
any ideas where i have got it wrong or if these scripts above are not working right.
cheers guys
- ComputerCraft | Programmable Computers for Minecraft
- → lebalusch's Content


