[Mod] Password Chest [1.3] [password_chest]

User avatar
ynong123
Member
 
Posts: 20
Joined: Fri Mar 11, 2016 13:24
Location: Malaysia
GitHub: ynong123
IRC: ynong123
In-game: ynong123

[Mod] Password Chest [1.3] [password_chest]

by ynong123 » Sat Jun 04, 2016 11:37

Image

Adds password chest that can protect your items.

Latest Version: 1.3
License: LGPL 2.1+ for code, CC-BY-SA 3.0 UNPORTED for textures.
Depends: default (can be found in minetest_game)

Download
1.3 (Latest): Download | GitHub
1.1: Download | GitHub
1.0: Download | GitHub

+ Screenshots


Tutorials


Crafting
Code: Select all
Wood  Mese Block  Wood
Wood  Gold Ingot  Wood --> Password Chest
Wood  Wood        Wood


Chat Commands
Code: Select all
/password_chest reset

Reset all of password chests in the world.

Code: Select all
/password_chest database

Open Password Chest Database.

Note: Only admins can use these commands.
Last edited by ynong123 on Thu Sep 01, 2016 09:16, edited 10 times in total.
 

User avatar
Krock
Developer
 
Posts: 4148
Joined: Thu Oct 03, 2013 07:48
Location: Switzerland
GitHub: SmallJoker

Re: [Mod] Password Chest [password_chest]

by Krock » Sat Jun 04, 2016 11:50

I had a similar idea two years ago. The security issue about the metadata is still the same. You could hash the password with a secure algorithm, so it's no longer possible to read the password and use it to open the chest.
Mod Search Engine - Mods by Krock - DuckDuckGo mod search bang: !mtmod <keyword here>
 

User avatar
ynong123
Member
 
Posts: 20
Joined: Fri Mar 11, 2016 13:24
Location: Malaysia
GitHub: ynong123
IRC: ynong123
In-game: ynong123

Re: [Mod] Password Chest [password_chest]

by ynong123 » Sat Jun 04, 2016 11:53

I will hash the password in the next update. Thanks for Krock.
 

User avatar
azekill_DIABLO
Member
 
Posts: 7460
Joined: Wed Oct 29, 2014 20:05
Location: OMICRON
GitHub: azekillDIABLO
In-game: azekill_DIABLO
 

User avatar
rubenwardy
Moderator
 
Posts: 5545
Joined: Tue Jun 12, 2012 18:11
Location: United Kingdom
GitHub: rubenwardy
IRC: rubenwardy
In-game: rubenwardy

Re: [Mod] Password Chest [password_chest]

by rubenwardy » Sat Jun 04, 2016 18:38

An even better solution is to store an identifier I'm the node and the passwords in a file. That way the hash is never sent to the client.
 

User avatar
rubenwardy
Moderator
 
Posts: 5545
Joined: Tue Jun 12, 2012 18:11
Location: United Kingdom
GitHub: rubenwardy
IRC: rubenwardy
In-game: rubenwardy

Re: [Mod] Password Chest [password_chest]

by rubenwardy » Sun Jun 05, 2016 14:52

Note that I haven't tested this

Code: Select all
local account = {
   store = {},
   counter = 0
}

--
-- Generates a random string of length 32, you can ignore this function
--
function account.genSalt()
   local Chars = {}
   for Loop = 0, 255 do
      Chars[Loop+1] = string.char(Loop)
   end
   local String = table.concat(Chars)

   local Built = {['.'] = Chars}

   local AddLookup = function(CharSet)
      local Substitute = string.gsub(String, '[^'..CharSet..']', '')
      local Lookup = {}
      for Loop = 1, string.len(Substitute) do
          Lookup[Loop] = string.sub(Substitute, Loop, Loop)
      end
      Built[CharSet] = Lookup

      return Lookup
   end

   local function srandom(Length, CharSet)
      -- Length (number)
      -- CharSet (string, optional); e.g. %l%d for lower case letters and digits

      local CharSet = CharSet or '.'

      if CharSet == '' then
         return ''
      else
         local Result = {}
         local Lookup = Built[CharSet] or AddLookup(CharSet)
         local Range = table.getn(Lookup)

         for Loop = 1,Length do
            Result[Loop] = Lookup[math.random(1, Range)]
         end

         return table.concat(Result)
      end
   end

   return srandom(32, "%l%d")
end

--
-- Creates a new account
--
function account.new(pass)
   account.counter = account.counter + 1
   local salt = account.genSalt()
   account.store[account.counter] = {
      hash = minetest.get_password_hash(salt, pass),
      salt = salt
   }
   account.save()
   return account.counter
end

--
-- Checks that the given password is the right one
--
function account.checkPassword(id, given)
   local stored = account.store[id]
   local tocheck = minetest.get_password_hash(stored.salt, given)
   return tocheck == stored.hash
end

--
-- Allows changing of password given old password
--
function account.changePassword(id, old, new)
   local stored = account.store[id]
   local tocheck = minetest.get_password_hash(stored.salt, old)
   if tocheck == stored.hash then
      local salt = account.genSalt()
      stored.salt = salt
      stored.hash = minetest.get_password_hash(salt, new)
      account.save()
   end
end

function account.init()
   local file = io.open(minetest.get_worldpath() .. "/password_chest_passwords.txt", "r")
   if file then
      local from_file = minetest.deserialize(file:read("*all"))
      file:close()
      if type(from_file) == "table" then
         account.store = from_file.store
         account.counter = from_file.counter
      end
   end
end

function account.save()
   local file = io.open(minetest.get_worldpath().."/password_chest_passwords.txt", "w")
   if file then
      file:write(minetest.serialize({
         store = account.store,
         counter = account.counter
      }))
      file:close()
   end
end

account.init()


When a user sets their password on a new chest

Code: Select all
local entered_password = fields["password"]
local entered_password_verify = fields["password_ver"]
if entered_password == entered_password_verify then
   local id = account.newAccount(entered_password)
   meta:set_int("acc_id", id)
else
   -- mismatching password and verify password
end


When you need to log a user in

Code: Select all
local id = meta:get_int("acc_id")
local entered_password = fields["password_old"]
if account.checkPassword(id, entered_password) then
   -- password matches!
else
   -- password doesn't match!
end


To change their password
Code: Select all
local id = meta:get_int("acc_id")
local pass_old = fields["password_old"]
local pass_new = fields["password_new"]
local pass_new_ver = fields["password_new_ver"]
if pass_new == pass_new_ver then
   if account.changePassword(id, pass_old, pass_new) then
      -- success
   else
      -- wrong old pass
   end
else
   -- mismatching password and verify password
end
 

Tallmantsu
New member
 
Posts: 2
Joined: Fri Apr 27, 2018 17:47
GitHub: Tallmantsu
IRC: Tallmantsu
In-game: Tallmantsu

Re: [Mod] Password Chest [1.3] [password_chest]

by Tallmantsu » Mon Apr 30, 2018 10:44

Hi

I'm new in Minetest and this is my first post, sorry if I m asking some basic stuff.
I encounter problems with the mod "password chest 1.3", when I use it I can't launch my server.
Here is the message :

2018-04-21 19:00:13: WARNING[Main]: BanManager: creating /home/bellinuxien/.minetest/worlds/Biz/ipban.txt
2018-04-21 19:00:13: WARNING[Main]: NodeDefManager: Ignoring CONTENT_IGNORE redefinition
2018-04-21 19:00:13: ERROR[Main]: ModError: Failed to load and run script from /home/bellinuxien/.minetest/games/rally-citoyen/mods/password_chest/init.lua:
2018-04-21 19:00:13: ERROR[Main]: ...inetest/games/rally-citoyen/mods/password_chest/init.lua:178: '}' expected (to close '{' at line 55) near 'end'
2018-04-21 19:00:13: ERROR[Main]: Voir debug.txt pour plus d'informations.

I tried to correct several things like adding '}' line 178, it was useless... Finally I succeeded in launching my server by removing "end" line 176. But an other problem appeared, when I dig chest the server crashes, like in "password chest 1.1.
Do you have any ideas ?
 


Return to Mod Releases



Who is online

Users browsing this forum: No registered users and 11 guests