Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[
- -- 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
Advertisement
Add Comment
Please, Sign In to add comment