The code for it would be something like shell.setDiskBootPassword("Password here")
This is a read-only snapshot of the ComputerCraft forums,
taken in April 2020.
[1.4] Disk Boot Password
Started by Zalerinian, 06 May 2012 - 01:33 PMPosted 06 May 2012 - 03:33 PM
As a suggestion to stop hackers, since there seems to be a great abundance of them, why not add a system that when it detects a floppy disk with a file named "startup" (or just if it has data, if you prefer) then it requires a password to work. This will make security systems much more secure.
The code for it would be something like shell.setDiskBootPassword("Password here")
The code for it would be something like shell.setDiskBootPassword("Password here")
Posted 06 May 2012 - 04:18 PM
Good idea, I'll get messing with BIOS.lua…
Posted 06 May 2012 - 04:39 PM
Heres the code. Replace password here with your password. Replace the file shell in .minecraft/mods/computercraft/lua/rom/programs/shell. Remove the txt extention first. :)/>/>
Posted 06 May 2012 - 08:32 PM
(sorry for my bad english)
Looks nice, but the password must be changeable in-game,
Looks nice, but the password must be changeable in-game,
This is a good idea, but i suggest something like a local file named "Bootpassword", which contains the password on each computer, because if you know the password, you can still hack every computer on the server. I'm working at this now, i will post it as soon as it's doneThe code for it would be something like shell.setDiskBootPassword("Password here")
Posted 06 May 2012 - 10:05 PM
As a suggestion to stop hackers, since there seems to be a great abundance of them, why not add a system that when it detects a floppy disk with a file named "startup" (or just if it has data, if you prefer) then it requires a password to work. This will make security systems much more secure.
The code for it would be something like shell.setDiskBootPassword("Password here")
Here
Spoiler
local parentShell = shell
local bExit = false
local sDir = (parentShell and parentShell.dir()) or ""
local sPath = (parentShell and parentShell.path()) or ".:/rom/programs"
local tAliases = (parentShell and parentShell.aliases()) or {}
local tProgramStack = {}
local shell = {}
local tEnv = {
["shell"] = shell,
}
-- Install shell API
function shell.setDiskBootPassword(password)
if fs.exists(".diskboot") then
fs.delete(".diskboot")
end
file = fs.open(".diskboot", "w")
file.write(password)
file.close()
end
function shell.run( _sCommand, ... )
local sPath = shell.resolveProgram( _sCommand )
if sPath ~= nil then
tProgramStack[#tProgramStack + 1] = sPath
local result = os.run( tEnv, sPath, ... )
tProgramStack[#tProgramStack] = nil
return result
else
print( "No such program" )
return false
end
end
function shell.exit()
bExit = true
end
function shell.dir()
return sDir
end
function shell.setDir( _sDir )
sDir = _sDir
end
function shell.path()
return sPath
end
function shell.setPath( _sPath )
sPath = _sPath
end
function shell.resolve( _sPath )
local sStartChar = string.sub( _sPath, 1, 1 )
if sStartChar == "/" or sStartChar == "" then
return fs.combine( "", _sPath )
else
return fs.combine( sDir, _sPath )
end
end
function shell.resolveProgram( _sCommand )
-- Substitute aliases firsts
if tAliases[ _sCommand ] ~= nil then
_sCommand = tAliases[ _sCommand ]
end
-- If the path is a global path, use it directly
local sStartChar = string.sub( _sCommand, 1, 1 )
if sStartChar == "/" or sStartChar == "" then
local sPath = fs.combine( "", _sCommand )
if fs.exists( sPath ) and not fs.isDir( sPath ) then
return sPath
end
return nil
end
-- Otherwise, look on the path variable
for sPath in string.gmatch(sPath, "[^:]+") do
sPath = fs.combine( shell.resolve( sPath ), _sCommand )
if fs.exists( sPath ) and not fs.isDir( sPath ) then
return sPath
end
end
-- Not found
return nil
end
function shell.programs( _bIncludeHidden )
local tItems = {}
-- Add programs from the path
for sPath in string.gmatch(sPath, "[^:]+") do
sPath = shell.resolve( sPath )
if fs.isDir( sPath ) then
local tList = fs.list( sPath )
for n,sFile in pairs( tList ) do
if not fs.isDir( fs.combine( sPath, sFile ) ) and
(_bIncludeHidden or string.sub( sFile, 1, 1 ) ~= ".") then
tItems[ sFile ] = true
end
end
end
end
-- Sort and return
local tItemList = {}
for sItem, b in pairs( tItems ) do
table.insert( tItemList, sItem )
end
table.sort( tItemList )
return tItemList
end
function shell.getRunningProgram()
if #tProgramStack > 0 then
return tProgramStack[#tProgramStack]
end
return nil
end
function shell.setAlias( _sCommand, _sProgram )
tAliases[ _sCommand ] = _sProgram
end
function shell.clearAlias( _sCommand )
tAliases[ _sCommand ] = nil
end
function shell.aliases()
-- Add aliases
local tCopy = {}
for sAlias, sCommand in pairs( tAliases ) do
tCopy[sAlias] = sCommand
end
return tCopy
end
print( os.version() )
-- If this is the toplevel shell, run the startup programs
if parentShell == nil then
-- Run the startup from the ROM first
local sRomStartup = shell.resolveProgram( "/rom/startup" )
if sRomStartup then
shell.run( sRomStartup )
end
-- Then run the user created startup, from the disks or the root
local sUserStartup = shell.resolveProgram( "/startup" )
for n,sSide in pairs( redstone.getSides() ) do
if disk.isPresent( sSide ) and disk.hasData( sSide ) then
local sDiskStartup = shell.resolveProgram( fs.combine(disk.getMountPath( sSide ), "startup") )
if sDiskStartup then
if fs.exists(".diskboot") then
file = fs.open(".diskboot", "r")
password = file.readAll()
file.close()
write("Password: ")
if not password == read() then
break
end
end
sUserStartup = sDiskStartup
break
end
end
end
if sUserStartup then
shell.run( sUserStartup )
end
end
-- Run any programs passed in as arguments
local tArgs = { ... }
if #tArgs > 0 then
shell.run( ... )
end
-- Read commands and execute them
local tCommandHistory = {}
while not bExit do
write( shell.dir() .. "> " )
local sLine = read( nil, tCommandHistory )
table.insert( tCommandHistory, sLine )
local tWords = {}
for match in string.gmatch(sLine, "[^ t]+") do
table.insert( tWords, match )
end
local sCommand = tWords[1]
if sCommand then
shell.run( sCommand, unpack( tWords, 2 ) )
end
end
-- If this is the toplevel shell, run the shutdown program
if parentShell == nil then
if shell.resolveProgram( "shutdown" ) then
shell.run( "shutdown" )
end
os.shutdown() -- just in case
end
I combined your suggestion, and Dirkus7's suggestion. Use
shell.setDiskBootPassword("Password here")
to create a file called .diskboot with "Password here"Unlike Sxw1212's shell program, this one gives each user their own password.
(Installed the same was as Sxw1212's shell)
EDIT:
Oops, forgot to replace the read() with read("*") and the password didn't work. Try this code, it reboots if u got it wrong
Spoiler
local parentShell = shell
local bExit = false
local sDir = (parentShell and parentShell.dir()) or ""
local sPath = (parentShell and parentShell.path()) or ".:/rom/programs"
local tAliases = (parentShell and parentShell.aliases()) or {}
local tProgramStack = {}
local shell = {}
local tEnv = {
["shell"] = shell,
}
-- Install shell API
function shell.setDiskBootPassword(password)
if fs.exists(".diskboot") then
fs.delete(".diskboot")
end
file = fs.open(".diskboot", "w")
file.write(password)
file.close()
end
function shell.setBootPassword(password)
if fs.exists(".boot") then
fs.delete(".boot")
end
file = fs.open(".boot", "w")
file.write(password)
file.close()
end
function shell.run( _sCommand, ... )
local sPath = shell.resolveProgram( _sCommand )
if sPath ~= nil then
tProgramStack[#tProgramStack + 1] = sPath
local result = os.run( tEnv, sPath, ... )
tProgramStack[#tProgramStack] = nil
return result
else
print( "No such program" )
return false
end
end
function shell.exit()
bExit = true
end
function shell.dir()
return sDir
end
function shell.setDir( _sDir )
sDir = _sDir
end
function shell.path()
return sPath
end
function shell.setPath( _sPath )
sPath = _sPath
end
function shell.resolve( _sPath )
local sStartChar = string.sub( _sPath, 1, 1 )
if sStartChar == "/" or sStartChar == "" then
return fs.combine( "", _sPath )
else
return fs.combine( sDir, _sPath )
end
end
function shell.resolveProgram( _sCommand )
-- Substitute aliases firsts
if tAliases[ _sCommand ] ~= nil then
_sCommand = tAliases[ _sCommand ]
end
-- If the path is a global path, use it directly
local sStartChar = string.sub( _sCommand, 1, 1 )
if sStartChar == "/" or sStartChar == "" then
local sPath = fs.combine( "", _sCommand )
if fs.exists( sPath ) and not fs.isDir( sPath ) then
return sPath
end
return nil
end
-- Otherwise, look on the path variable
for sPath in string.gmatch(sPath, "[^:]+") do
sPath = fs.combine( shell.resolve( sPath ), _sCommand )
if fs.exists( sPath ) and not fs.isDir( sPath ) then
return sPath
end
end
-- Not found
return nil
end
function shell.programs( _bIncludeHidden )
local tItems = {}
-- Add programs from the path
for sPath in string.gmatch(sPath, "[^:]+") do
sPath = shell.resolve( sPath )
if fs.isDir( sPath ) then
local tList = fs.list( sPath )
for n,sFile in pairs( tList ) do
if not fs.isDir( fs.combine( sPath, sFile ) ) and
(_bIncludeHidden or string.sub( sFile, 1, 1 ) ~= ".") then
tItems[ sFile ] = true
end
end
end
end
-- Sort and return
local tItemList = {}
for sItem, b in pairs( tItems ) do
table.insert( tItemList, sItem )
end
table.sort( tItemList )
return tItemList
end
function shell.getRunningProgram()
if #tProgramStack > 0 then
return tProgramStack[#tProgramStack]
end
return nil
end
function shell.setAlias( _sCommand, _sProgram )
tAliases[ _sCommand ] = _sProgram
end
function shell.clearAlias( _sCommand )
tAliases[ _sCommand ] = nil
end
function shell.aliases()
-- Add aliases
local tCopy = {}
for sAlias, sCommand in pairs( tAliases ) do
tCopy[sAlias] = sCommand
end
return tCopy
end
print( os.version() )
if fs.exists(".boot") then
file = fs.open(".boot", "r")
password = file.readAll()
file.close()
write("Password: ")
if password == read("*") then else
os.reboot()
end
end
-- If this is the toplevel shell, run the startup programs
if parentShell == nil then
-- Run the startup from the ROM first
local sRomStartup = shell.resolveProgram( "/rom/startup" )
if sRomStartup then
shell.run( sRomStartup )
end
-- Then run the user created startup, from the disks or the root
local sUserStartup = shell.resolveProgram( "/startup" )
for n,sSide in pairs( redstone.getSides() ) do
if disk.isPresent( sSide ) and disk.hasData( sSide ) then
local sDiskStartup = shell.resolveProgram( fs.combine(disk.getMountPath( sSide ), "startup") )
if sDiskStartup then
if fs.exists(".diskboot") then
file = fs.open(".diskboot", "r")
password = file.readAll()
file.close()
write("Password: ")
input = read("*")
end
if input == password then
sUserStartup = sDiskStartup
else
os.reboot()
end
break
end
end
end
if sUserStartup then
shell.run( sUserStartup )
end
end
-- Run any programs passed in as arguments
local tArgs = { ... }
if #tArgs > 0 then
shell.run( ... )
end
-- Read commands and execute them
local tCommandHistory = {}
while not bExit do
write( shell.dir() .. "> " )
local sLine = read( nil, tCommandHistory )
table.insert( tCommandHistory, sLine )
local tWords = {}
for match in string.gmatch(sLine, "[^ t]+") do
table.insert( tWords, match )
end
local sCommand = tWords[1]
if sCommand then
shell.run( sCommand, unpack( tWords, 2 ) )
end
end
-- If this is the toplevel shell, run the shutdown program
if parentShell == nil then
if shell.resolveProgram( "shutdown" ) then
shell.run( "shutdown" )
end
os.shutdown() -- just in case
end
Just in case, i added:
setBootPassword("password here") --If you type in something, a password is required to boot
setDiskBootPassword("password here") --If you type in something, a password is required to boot with a disk
Posted 07 May 2012 - 02:23 AM
As a suggestion to stop hackers, since there seems to be a great abundance of them, why not add a system that when it detects a floppy disk with a file named "startup" (or just if it has data, if you prefer) then it requires a password to work. This will make security systems much more secure.
The code for it would be something like shell.setDiskBootPassword("Password here")
HereSpoiler
local parentShell = shell local bExit = false local sDir = (parentShell and parentShell.dir()) or "" local sPath = (parentShell and parentShell.path()) or ".:/rom/programs" local tAliases = (parentShell and parentShell.aliases()) or {} local tProgramStack = {} local shell = {} local tEnv = { ["shell"] = shell, } -- Install shell API function shell.setDiskBootPassword(password) if fs.exists(".diskboot") then fs.delete(".diskboot") end file = fs.open(".diskboot", "w") file.write(password) file.close() end function shell.run( _sCommand, ... ) local sPath = shell.resolveProgram( _sCommand ) if sPath ~= nil then tProgramStack[#tProgramStack + 1] = sPath local result = os.run( tEnv, sPath, ... ) tProgramStack[#tProgramStack] = nil return result else print( "No such program" ) return false end end function shell.exit() bExit = true end function shell.dir() return sDir end function shell.setDir( _sDir ) sDir = _sDir end function shell.path() return sPath end function shell.setPath( _sPath ) sPath = _sPath end function shell.resolve( _sPath ) local sStartChar = string.sub( _sPath, 1, 1 ) if sStartChar == "/" or sStartChar == "" then return fs.combine( "", _sPath ) else return fs.combine( sDir, _sPath ) end end function shell.resolveProgram( _sCommand ) -- Substitute aliases firsts if tAliases[ _sCommand ] ~= nil then _sCommand = tAliases[ _sCommand ] end -- If the path is a global path, use it directly local sStartChar = string.sub( _sCommand, 1, 1 ) if sStartChar == "/" or sStartChar == "" then local sPath = fs.combine( "", _sCommand ) if fs.exists( sPath ) and not fs.isDir( sPath ) then return sPath end return nil end -- Otherwise, look on the path variable for sPath in string.gmatch(sPath, "[^:]+") do sPath = fs.combine( shell.resolve( sPath ), _sCommand ) if fs.exists( sPath ) and not fs.isDir( sPath ) then return sPath end end -- Not found return nil end function shell.programs( _bIncludeHidden ) local tItems = {} -- Add programs from the path for sPath in string.gmatch(sPath, "[^:]+") do sPath = shell.resolve( sPath ) if fs.isDir( sPath ) then local tList = fs.list( sPath ) for n,sFile in pairs( tList ) do if not fs.isDir( fs.combine( sPath, sFile ) ) and (_bIncludeHidden or string.sub( sFile, 1, 1 ) ~= ".") then tItems[ sFile ] = true end end end end -- Sort and return local tItemList = {} for sItem, b in pairs( tItems ) do table.insert( tItemList, sItem ) end table.sort( tItemList ) return tItemList end function shell.getRunningProgram() if #tProgramStack > 0 then return tProgramStack[#tProgramStack] end return nil end function shell.setAlias( _sCommand, _sProgram ) tAliases[ _sCommand ] = _sProgram end function shell.clearAlias( _sCommand ) tAliases[ _sCommand ] = nil end function shell.aliases() -- Add aliases local tCopy = {} for sAlias, sCommand in pairs( tAliases ) do tCopy[sAlias] = sCommand end return tCopy end print( os.version() ) -- If this is the toplevel shell, run the startup programs if parentShell == nil then -- Run the startup from the ROM first local sRomStartup = shell.resolveProgram( "/rom/startup" ) if sRomStartup then shell.run( sRomStartup ) end -- Then run the user created startup, from the disks or the root local sUserStartup = shell.resolveProgram( "/startup" ) for n,sSide in pairs( redstone.getSides() ) do if disk.isPresent( sSide ) and disk.hasData( sSide ) then local sDiskStartup = shell.resolveProgram( fs.combine(disk.getMountPath( sSide ), "startup") ) if sDiskStartup then if fs.exists(".diskboot") then file = fs.open(".diskboot", "r") password = file.readAll() file.close() write("Password: ") if not password == read() then break end end sUserStartup = sDiskStartup break end end end if sUserStartup then shell.run( sUserStartup ) end end -- Run any programs passed in as arguments local tArgs = { ... } if #tArgs > 0 then shell.run( ... ) end -- Read commands and execute them local tCommandHistory = {} while not bExit do write( shell.dir() .. "> " ) local sLine = read( nil, tCommandHistory ) table.insert( tCommandHistory, sLine ) local tWords = {} for match in string.gmatch(sLine, "[^ t]+") do table.insert( tWords, match ) end local sCommand = tWords[1] if sCommand then shell.run( sCommand, unpack( tWords, 2 ) ) end end -- If this is the toplevel shell, run the shutdown program if parentShell == nil then if shell.resolveProgram( "shutdown" ) then shell.run( "shutdown" ) end os.shutdown() -- just in case end
I combined your suggestion, and Dirkus7's suggestion. Useto create a file called .diskboot with "Password here"shell.setDiskBootPassword("Password here")
Unlike Sxw1212's shell program, this one gives each user their own password.
(Installed the same was as Sxw1212's shell)
EDIT:
Oops, forgot to replace the read() with read("*") and the password didn't work. Try this code, it reboots if u got it wrongSpoiler
local parentShell = shell local bExit = false local sDir = (parentShell and parentShell.dir()) or "" local sPath = (parentShell and parentShell.path()) or ".:/rom/programs" local tAliases = (parentShell and parentShell.aliases()) or {} local tProgramStack = {} local shell = {} local tEnv = { ["shell"] = shell, } -- Install shell API function shell.setDiskBootPassword(password) if fs.exists(".diskboot") then fs.delete(".diskboot") end file = fs.open(".diskboot", "w") file.write(password) file.close() end function shell.setBootPassword(password) if fs.exists(".boot") then fs.delete(".boot") end file = fs.open(".boot", "w") file.write(password) file.close() end function shell.run( _sCommand, ... ) local sPath = shell.resolveProgram( _sCommand ) if sPath ~= nil then tProgramStack[#tProgramStack + 1] = sPath local result = os.run( tEnv, sPath, ... ) tProgramStack[#tProgramStack] = nil return result else print( "No such program" ) return false end end function shell.exit() bExit = true end function shell.dir() return sDir end function shell.setDir( _sDir ) sDir = _sDir end function shell.path() return sPath end function shell.setPath( _sPath ) sPath = _sPath end function shell.resolve( _sPath ) local sStartChar = string.sub( _sPath, 1, 1 ) if sStartChar == "/" or sStartChar == "" then return fs.combine( "", _sPath ) else return fs.combine( sDir, _sPath ) end end function shell.resolveProgram( _sCommand ) -- Substitute aliases firsts if tAliases[ _sCommand ] ~= nil then _sCommand = tAliases[ _sCommand ] end -- If the path is a global path, use it directly local sStartChar = string.sub( _sCommand, 1, 1 ) if sStartChar == "/" or sStartChar == "" then local sPath = fs.combine( "", _sCommand ) if fs.exists( sPath ) and not fs.isDir( sPath ) then return sPath end return nil end -- Otherwise, look on the path variable for sPath in string.gmatch(sPath, "[^:]+") do sPath = fs.combine( shell.resolve( sPath ), _sCommand ) if fs.exists( sPath ) and not fs.isDir( sPath ) then return sPath end end -- Not found return nil end function shell.programs( _bIncludeHidden ) local tItems = {} -- Add programs from the path for sPath in string.gmatch(sPath, "[^:]+") do sPath = shell.resolve( sPath ) if fs.isDir( sPath ) then local tList = fs.list( sPath ) for n,sFile in pairs( tList ) do if not fs.isDir( fs.combine( sPath, sFile ) ) and (_bIncludeHidden or string.sub( sFile, 1, 1 ) ~= ".") then tItems[ sFile ] = true end end end end -- Sort and return local tItemList = {} for sItem, b in pairs( tItems ) do table.insert( tItemList, sItem ) end table.sort( tItemList ) return tItemList end function shell.getRunningProgram() if #tProgramStack > 0 then return tProgramStack[#tProgramStack] end return nil end function shell.setAlias( _sCommand, _sProgram ) tAliases[ _sCommand ] = _sProgram end function shell.clearAlias( _sCommand ) tAliases[ _sCommand ] = nil end function shell.aliases() -- Add aliases local tCopy = {} for sAlias, sCommand in pairs( tAliases ) do tCopy[sAlias] = sCommand end return tCopy end print( os.version() ) if fs.exists(".boot") then file = fs.open(".boot", "r") password = file.readAll() file.close() write("Password: ") if password == read("*") then else os.reboot() end end -- If this is the toplevel shell, run the startup programs if parentShell == nil then -- Run the startup from the ROM first local sRomStartup = shell.resolveProgram( "/rom/startup" ) if sRomStartup then shell.run( sRomStartup ) end -- Then run the user created startup, from the disks or the root local sUserStartup = shell.resolveProgram( "/startup" ) for n,sSide in pairs( redstone.getSides() ) do if disk.isPresent( sSide ) and disk.hasData( sSide ) then local sDiskStartup = shell.resolveProgram( fs.combine(disk.getMountPath( sSide ), "startup") ) if sDiskStartup then if fs.exists(".diskboot") then file = fs.open(".diskboot", "r") password = file.readAll() file.close() write("Password: ") input = read("*") end if input == password then sUserStartup = sDiskStartup else os.reboot() end break end end end if sUserStartup then shell.run( sUserStartup ) end end -- Run any programs passed in as arguments local tArgs = { ... } if #tArgs > 0 then shell.run( ... ) end -- Read commands and execute them local tCommandHistory = {} while not bExit do write( shell.dir() .. "> " ) local sLine = read( nil, tCommandHistory ) table.insert( tCommandHistory, sLine ) local tWords = {} for match in string.gmatch(sLine, "[^ t]+") do table.insert( tWords, match ) end local sCommand = tWords[1] if sCommand then shell.run( sCommand, unpack( tWords, 2 ) ) end end -- If this is the toplevel shell, run the shutdown program if parentShell == nil then if shell.resolveProgram( "shutdown" ) then shell.run( "shutdown" ) end os.shutdown() -- just in case end
Just in case, i added:setBootPassword("password here") --If you type in something, a password is required to boot setDiskBootPassword("password here") --If you type in something, a password is required to boot with a disk
Funny thing is my server already has that, i was saying it should be officially in the mod. :)/>/>
Posted 22 May 2012 - 09:48 PM
Good job, I never thought about that.