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

How I can save data from 1prog to second?

Started by DoGzY, 16 April 2013 - 09:06 AM
DoGzY #1
Posted 16 April 2013 - 11:06 AM
So guys,I don't knwo how I can save data from first programm to second.For example: User entered his data to one programs, then opens second program and it's asks for data(username and pass).I want to do li ke this: oyu entered Username and password in one programm then opens second and to acces computer need to type that pass and login which you entered at firs programm.Someone can help me?
Spongy141 #2
Posted 16 April 2013 - 11:32 AM
Wow, could you spell better next time? But do.

function username()
  file = fs.open(".username",r") -- .username will be the users username file
  local user = file.readLine()
  file.close()
end
function password()
  file = fs.open(".password","r") -- .password will be the users password file
  local pass = file.readLine()
  file.close()
end
term.write("Username: ")
local name = read()
username()
if name == user then
  term.write("Password: ")
  local password = read()
  password()
  if password == pass then
	 -- Stuff
  else
	 -- Stuff
  end
else
  --stuff
end
Now thats using fs API, if you only want to use one fill you need to define all those variables in your fill, then do "os.loadAPI(FILENAME)"
H4X0RZ #3
Posted 16 April 2013 - 11:58 AM
You can do it with an mySQL db ^^
(you must haveenabled the http api)

PHP Code: (I don't know if it's right cuz I write from the memory
Spoiler

<?php

$username = $_GET["user"]
$password = $_GET["pass"]

$connection = mysql_connect("ip", "name, "password")

mysql_select_db("test")

$select = mysql_query("SELECT id FROM test WHERE 'username = $username and password = $password'")

$result = mysql_num_rows($select)

if ($result == 1) {
echo "success"
}
if ($result == 0) {
echo "denied"
}
?>

And in Computercraft:
Spoiler

term.clear()
term.setCursorPos(1,1)
termwrite("Username:")
name = read()
print(newLine)
term.write("Password:")
pass = read("*")
connection_data = ("http://localhost/login.php?user="..name.."&pass="..pass)
connection = http.get(connection)
file = connection.readLine()
if file == "success" then 
print("Wlcome "..name)
elseif file == "denied" then
print("Username or password wrong")
else
print("Intern server problem. Please restart login")
end

I hope It's helpfull

(Please correct me, if i did something wrong :)/> )
Sariaz #4
Posted 16 April 2013 - 02:48 PM
A third way you could do this is to have the first program send the data to a second computer to be stored either of the previously mentioned ways. Then the second program would ask the second computer weather or not it was correct.
Spongy141 #5
Posted 16 April 2013 - 02:57 PM
^
That way (if on a server) is not safe. Since anyone can just have computers receiving data from all channels… why they would go through all the effort, idk, but still they might, so I wouldnt use that way at all.
Sammich Lord #6
Posted 16 April 2013 - 02:58 PM
You can do it with an mySQL db ^^
(you must haveenabled the http api)

PHP Code: (I don't know if it's right cuz I write from the memory
Spoiler

<?php

$username = $_GET["user"]
$password = $_GET["pass"]

$connection = mysql_connect("ip", "name, "password")

mysql_select_db("test")

$select = mysql_query("SELECT id FROM test WHERE 'username = $username and password = $password'")

$result = mysql_num_rows($select)

if ($result == 1) {
echo "success"
}
if ($result == 0) {
echo "denied"
}
?>

And in Computercraft:
Spoiler

term.clear()
term.setCursorPos(1,1)
termwrite("Username:")
name = read()
print(newLine)
term.write("Password:")
pass = read("*")
connection_data = ("http://localhost/login.php?user="..name.."&pass="..pass)
connection = http.get(connection)
file = connection.readLine()
if file == "success" then
print("Wlcome "..name)
elseif file == "denied" then
print("Username or password wrong")
else
print("Intern server problem. Please restart login")
end

I hope It's helpfull

(Please correct me, if i did something wrong :)/> )
You forgot your semi-colons in the PHP code.
Sariaz #7
Posted 16 April 2013 - 03:15 PM
^
That way (if on a server) is not safe. Since anyone can just have computers receiving data from all channels… why they would go through all the effort, idk, but still they might, so I wouldnt use that way at all.

I though if u used rednet.send only the computer being sent to could receive the data is this not true?
Spongy141 #8
Posted 16 April 2013 - 03:34 PM
^
True, but if your having a server computer full of accounts and passwords, using rednet.send is a lot harder then just doing rednet.broadcast, since everytime they have the add a new ID to the list of computers. Yes it is possible, but takes longer. Its a nice idea, but requires (if on a large server) a staff that ONLY monitors user accounts and passwords… when all you have to do is use fs api…
Sariaz #9
Posted 16 April 2013 - 03:41 PM
yes mainly when I see topics like this I post other ways of doing things that are not mentioned so that people are exposed to other ideas that may spark other ideas or not. I started doing this after seeing where roblox went when people stopped caring about new ways of doing things or even programming at all :P/>. Also my idea would be best if many computers all wanted to access the same users and passwords since they'd have to communicate anyways or have separate manually updated lists.
Spongy141 #10
Posted 16 April 2013 - 03:53 PM
^
Actually after making reasons why using the account thing over rednet, I was thinking of making a a sycure rednet account system…
*Starts making the program*
Never mind to much work :P/>
Sariaz #11
Posted 16 April 2013 - 03:55 PM
:P/> although what you could do is use your normal encryption ideas to send an encrypted msg to server via .send then if it checks out add the sender to a list of approved computers.
Spongy141 #12
Posted 16 April 2013 - 04:02 PM
My encryption ideas? Lol I posted that a while ago. Have you been stalking me?
Sariaz #13
Posted 16 April 2013 - 04:21 PM
No but u sugested using broadcast so therfore you would have to encrypt it therefore u have ideas how to
H4X0RZ #14
Posted 17 April 2013 - 01:51 AM
You can do it with an mySQL db ^^
(you must haveenabled the http api)

PHP Code: (I don't know if it's right cuz I write from the memory
Spoiler

<?php

$username = $_GET["user"]
$password = $_GET["pass"]

$connection = mysql_connect("ip", "name, "password")

mysql_select_db("test")

$select = mysql_query("SELECT id FROM test WHERE 'username = $username and password = $password'")

$result = mysql_num_rows($select)

if ($result == 1) {
echo "success"
}
if ($result == 0) {
echo "denied"
}
?>

And in Computercraft:
Spoiler

term.clear()
term.setCursorPos(1,1)
termwrite("Username:")
name = read()
print(newLine)
term.write("Password:")
pass = read("*")
connection_data = ("http://localhost/login.php?user="..name.."&pass="..pass)
connection = http.get(connection)
file = connection.readLine()
if file == "success" then
print("Wlcome "..name)
elseif file == "denied" then
print("Username or password wrong")
else
print("Intern server problem. Please restart login")
end

I hope It's helpfull

(Please correct me, if i did something wrong :)/>/> )
You forgot your semi-colons in the PHP code.

Sorry, I will correct it today ^^

BTW, are the other things right(PHP and CC)?
Bubba #15
Posted 17 April 2013 - 05:41 AM
You can do it with an mySQL db ^^
(you must haveenabled the http api)

PHP Code: (I don't know if it's right cuz I write from the memory
Spoiler

<?php

$username = $_GET["user"]
$password = $_GET["pass"]

$connection = mysql_connect("ip", "name, "password")

mysql_select_db("test")

$select = mysql_query("SELECT id FROM test WHERE 'username = $username and password = $password'")

$result = mysql_num_rows($select)

if ($result == 1) {
echo "success"
}
if ($result == 0) {
echo "denied"
}
?>

And in Computercraft:
Spoiler

term.clear()
term.setCursorPos(1,1)
termwrite("Username:")
name = read()
print(newLine)
term.write("Password:")
pass = read("*")
connection_data = ("http://localhost/login.php?user="..name.."&amp;pass="..pass)
connection = http.get(connection)
file = connection.readLine()
if file == "success" then
print("Wlcome "..name)
elseif file == "denied" then
print("Username or password wrong")
else
print("Intern server problem. Please restart login")
end

I hope It's helpfull

(Please correct me, if i did something wrong :)/>/>/> )
You forgot your semi-colons in the PHP code.

Sorry, I will correct it today ^^

BTW, are the other things right(PHP and CC)?

Didn't read the whole thing, but this is not right:
connection_data = ("http://localhost/login.php?user="..name.."&pass="..pass)
connection = http.get(connection)