Login

My doubts, even to myself, is stupid. But I can not do this work with the Corona. I have an app and this app takes data from the internet. These data are available only to subscribers.

How to make a login function in the App? I am not able to do this.
I looked for examples in the templates, but I did not found.

Consider a simple page with autentication as example. If user & login == some data in my Database, I send information back to App.

Useful Examples?

Thnaks!

[import]uid: 9133 topic_id: 12908 reply_id: 312908[/import]

There are many ways to do this, and most are beyond the scope of just Corona as they are generic methods for all platforms.

One method that I am using for one of my apps currently is basic access authentication - http://en.wikipedia.org/wiki/Basic_access_authentication - I can’t tell you how it works on the server side as I didn’t set that part up, I just login, however as I understand it is fairly simple if you know your way around web development.

Once that end is set up logging in is fairly straight forward from the app side. You will need to generate a token using an entered username and password by using the Mime lib.

  
local mime = require( "mime" )  
  
local username = "bob@example.com"  
local password = "12345"  
  
local token = mime.b64( username .. ":" .. password )  
  

With that token you can then access secure urls:

  
 local http = require( "socket.http" )  
  
 local response = {}  
  
 local b, c, h = http.request   
 {   
 url = "http://www.securesite.com/users/me.json",  
 headers = { Authorization = "Basic " .. token },  
 sink = ltn12.sink.table( response )  
 }  
  

This will then download whatever is at that URL and place it into the “response” table. Naturally you will have to then deal with it in your app, and check the “b”, “c” and “h” values if things seem to have gone wrong.

[import]uid: 5833 topic_id: 12908 reply_id: 47376[/import]

I’m not sure of any good examples, but there are a couple of ways to do it.

One is to use the native.webPopup API. In this case you have a login.html file (or .php or .asp whatever you’re using) that you load into the web popup, let the login to the server and as part of the submission, a function in your app will get called back and you could take that response and determine if they are logged in.

If you want to keep them logged in, write a little file out to your documents area with their username and password and then if the file exists, read it, add the values as get parameters on the URL to your login page. Not the most secure, but you could obscure it if that’s a concern.

The other option is to use the the Async HTTP Request API. In a similar fashion you would have a page on your server that takes get or post parameters build your own Corona form using native.textFields to collect the login information, send it as a get or put request using the Async HTTp stuff to the server, return a response if it was successful or not and the call back routine can move on.

FWIW, I’m working on a game that I want to have some multi-player features going on and I will probably go the Async HTTP Request route. I’m going to set things up in a REST style API using PHP and MySQL on the backend and just set it up to return JSON objects and on a successful login, I’ll send back a session ID along with their data, score, etc. [import]uid: 19626 topic_id: 12908 reply_id: 47375[/import]

Thanks for these sugestions. I will try and I give a feedback about the problems I founded.

Thanks! [import]uid: 9133 topic_id: 12908 reply_id: 47406[/import]