This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
___'s profile picture

SubOS [Archived]

Started by ___, 15 February 2016 - 10:09 PM
___ #1
Posted 15 February 2016 - 11:09 PM
Nothing here.
Edited on 13 May 2017 - 04:01 PM
FUNCTION MAN! #2
Posted 15 February 2016 - 11:54 PM
From the screenshots I can see that you aren't hiding your passwords.

You can do this with the following snippet:


local pass = read(replacement or '*')

Where replacement is the character you want to show up instead of the password.

EDIT: I took the time to read through it.

/etc/bios will never work. Ever. That's because you're comparing a number

local yn = tonumber(read())

With two undefined variables,

if yn == y then
  -snip-
elseif yn == n then
  -snip-
end

tonumber() will return nil, and the variable y (the first comparison) is also nil, so it'll always prompt for choices.

In /startup, you flush the file before writing.

Instead of using read() for single-character input, you should use pullEvent('char') instead.


INDENT YOUR CODE! I absolutely can't point out how important this is. If your code is not indented, it's harder to tell blocks apart, and since none of your files have a '.lua' extension, it's pretty awful to read in most text editors, since the file will look like this.

In /etc/shell,
  • you're comparing a file handle (shell_can_run = fs.open('/etc/shell_can_run', 'r')) with a number (1)
  • Your attempt at artificial“security” is pretty much worthless. You protect only against commands that are exactly edit /etc/bios. There are many other ways to edit the file /etc/bios, such as /rom/../etc/bios.

Must I also say that all attempts of actually using the login system are going to result in failure? I'm just going to annotate the source and put it in a hastebin here since it's too long to fit in this post.
Edited on 15 February 2016 - 11:21 PM
___ #3
Posted 16 February 2016 - 01:23 AM
I will fix, again, Version: Beta v1
hbomb79 #4
Posted 16 February 2016 - 03:12 AM
The 'backup' script will not work correctly, on line 12 you compare the input of the user to the variable 'y'

The variable 'y' is not defined and thus the 'else' clause will always be executed, regardless of the user's input. To compare if the key they stuck (followed by enter) was the letter 'y', I propose:


local yn = read():lower()
if yn == "y" then
  print("YES")
else
  print("NO")
end

Next, bios.lua… technically not a BIOS but whatever. problems:

line 12 will not work for the same reason as described above. With an exception, you are doing tonumber(read()) which makes absolutely no sense. You aren't treating the input as a number as you are trying to detect if they typed 'y', which is a string, not a number!

Similarly, line 42 will fail causing 'your choice was unknown' to be printed… for ever. Testing is important!

Right, let's move onto 'boot'. This one is… interesting

Firstly, line 9. This makes little sense, fs.open() will open a file. The first argument is the path to open which at this moment is a random number between 1 and 100… what. Either you have files 1-100 sitting on your computer or this is mistake. also you never close the line 9 fs.open or the line 15 fs.open… these should be closed.

I simply cannot make any sense from this boot file, on lines 22 and 23 in your else clause you write to the file the entered usernames and password (registration maybe??), but you are using 'tonumber' which will return nil if there username or password isn't just a string of number… which it likely won't be.


I got annoyed at the lack of indentation after this and gave up. I feel that before attempting a so called 'Secure user based operating system' you should actually get familiar with Lua. It is very difficult to make an OS, nevermind a 'user based' one which is also secure.

Apologies if I came across aggressively, I do not intend to. Good luck fixing!