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

If statement caps sensitive

Started by Microwarrior, 31 December 2015 - 08:23 PM
Microwarrior #1
Posted 31 December 2015 - 09:23 PM
Does anyone know how to make a if statement not caps sensitive? I am making a login program. Help appreciated! :)/>
Creator #2
Posted 31 December 2015 - 09:24 PM
You don't. if is just if and not IF. That is how Lua works.
Microwarrior #3
Posted 31 December 2015 - 09:32 PM
You don't. if is just if and not IF. That is how Lua works.

I has hoping if anyone know of any code that could do the comparison or convert all uppercase letters to lowercase or vice versa, but is wont be the end of the world is users need to get the capitals correct.
Creator #4
Posted 31 December 2015 - 09:33 PM
string.lower(text) will make text lower case.
InDieTasten #5
Posted 31 December 2015 - 09:38 PM
You can convert a string to lower case ->


input1 = read() -- i.e. "Hello"
input2 = read() -- i.e. "hELLo"

lowercase1 = string.lower(input1) -- will be "hello"
lowercase2 = string.lower(input2) -- will be "hello"

if(lowercase1 == lowercase2) then
  -- there you go. this block will be executed, when your inputs match in non-case-sensitive manner
end


When dealing with passwords and things, you should consider not to do this, since you loose entropy and therefor security.
So there will be much more ways to get into a single account. i mean, in computercraft this has no effect, but sticking to good practices is always a nice thing to do.
Microwarrior #6
Posted 31 December 2015 - 09:38 PM
string.lower(text) will make text lower case.

Thank you! :)/>
Edited on 31 December 2015 - 08:39 PM
Microwarrior #7
Posted 31 December 2015 - 09:44 PM
You can convert a string to lower case ->


input1 = read() -- i.e. "Hello"
input2 = read() -- i.e. "hELLo"

lowercase1 = string.lower(input1) -- will be "hello"
lowercase2 = string.lower(input2) -- will be "hello"

if(lowercase1 == lowercase2) then
  -- there you go. this block will be executed, when your inputs match in non-case-sensitive manner
end


When dealing with passwords and things, you should consider not to do this, since you loose entropy and therefor security.
So there will be much more ways to get into a single account. i mean, in computercraft this has no effect, but sticking to good practices is always a nice thing to do.

I am creating a multi-user login system I am going to make the usernames not case sensitive but the passwords are, as is standard practice. Also, for security the passwords are stored in a hashed format preventing non-caps comparison.