[Mod] Password Chest [1.3] [password_chest]

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

[Mod] Password Chest [1.3] [password_chest]

by ynong123 » Post

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
Spoiler
ImageImageImageImageImage

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: 4650
Joined: Thu Oct 03, 2013 07:48
GitHub: SmallJoker
Location: Switzerland
Contact:

Re: [Mod] Password Chest [password_chest]

by Krock » Post

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.
Look, I programmed a bug for you. >> 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
GitHub: ynong123
IRC: ynong123
In-game: ynong123
Location: Malaysia

Re: [Mod] Password Chest [password_chest]

by ynong123 » Post

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

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

Re: [Mod] Password Chest [password_chest]

by azekill_DIABLO » Post

The next wave in security mods!
Gone, but not dead. Contact me on discord: azekill_DIABLO#6565
DMs are always open if you want to get in touch!

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

Re: [Mod] Password Chest [password_chest]

by rubenwardy » Post

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.
Renewed Tab (my browser add-on) | Donate | Mods | Minetest Modding Book

Hello profile reader

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

Re: [Mod] Password Chest [password_chest]

by rubenwardy » Post

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
Renewed Tab (my browser add-on) | Donate | Mods | Minetest Modding Book

Hello profile reader

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 » Post

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 ?

chuia
New member
Posts: 5
Joined: Wed May 27, 2020 16:07
GitHub: ezemar
In-game: chuia

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

by chuia » Post

Tallmantsu wrote:
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 ?

Anyone here knows if there's a new mod's release available? I have the same problem when I dig it & when I try to unlock it with correct password, nothing happens

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

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

by rubenwardy » Post

As an alternative, there's locks: https://content.minetest.net/packages/Sokomine/locks/

It supports password-based chests.

Worth noting that the Password Chest mod is missing features that would make it more secure - Minetest has supported private meta data for a long time
Renewed Tab (my browser add-on) | Donate | Mods | Minetest Modding Book

Hello profile reader

Post Reply

Who is online

Users browsing this forum: Google [Bot] and 43 guests