Business App: Login and Password Encryption Sample

Yeah good idea! I thought about doing that too, I’ll set up an html form real quick and see what happens.

Fixed! I was closing the connection too early… Silly me. New problem arose though. The script seems to be working with the app and test form. When the script is called from the app, it creates a new row in the USER table of my database, but all the columns/attributes are empty! Whereas while calling the script from the test html form, it works fine. I now get this as output in the console:

16:24:18.571  Upload complete!
16:24:18.571  table: 0B209878
 

Fixed. I don’t know why having

local headers = {} headers["Content-Type"] = "application/json"

was affecting it… I commented it out and it now works! The data from the textfields are now successfully being updated into the database.

To a new topic, is there a way to show some sort of loading progress (like the little generic wheel) while the network.request() is being process?

This probably should be a new topic. But we have three options. There is a native.setActivtyIndicator(). You would call it right before you call network.request() and then in your call back function, call it again to cancel it. Pass it true if you want it, false to cancel. See: https://docs.coronalabs.com/api/library/native/setActivityIndicator.html

Since this native, it’s going to shutdown the whole screen until it completes.

There is a widget.newSpinner() that gives you customization abilities and it’s OpenGL based which means it doesn’t have to sit on top and take over the UI. See: https://docs.coronalabs.com/api/library/widget/newSpinner.html

And also in the widget library, is a widget.newProgressView(). Again this is an OpenGL based item which creates display objects. This would be useful if you’re downloading a file. network.request() does support download progress and you can catch these events in your network.request()'s event listener and update it as you get progress events.

But for a login thing, a progress bar isn’t a good choice for a UI option. Depending on how fast the login takes, the native.setActivityIndicator() could create a flash if the login is pretty quick. If you know its going to take a couple of seconds then it would be fine.

Rob

Thanks for the tips, I’ll be sticking for the activityIndicator for now.

Back to things related to logging in and account creation, is there a way for the app to recognize a session was already started? Like a “remember me” type deal, where if you’ve logged in before, it takes you straight to the main screen instead of the log in screen? I was thinking maybe a local database or something of the sort, but I’m unsure as to what the right way to approach this would be.

Anyhow, I’d like to thank you again and let you know how much I appreciate your insight! I was honestly considering switching to a new platform and relearning a whole new language, not because of the lack of capability of corona, but because of how little help I could find (sample code, forum posts) about the problems I was having, compared to other platforms where there is an abundance of tutorials and samples out there for pretty much everything really, as all these things have already been done before in said platforms. If it weren’t for your help, I’d probably be learning java and working with android studio (not xcode because I don’t own a mac) right now! So again, thank you very much!

As far as keeping track of if the user has already logged in, it’s a matter of you saving a file if they successfully logged in. Then on app start (and potentially app resume if you expire the login after a point), read that saved file and see if the person is logged in or not. This is a great way to also keep track of the first time someone ran the app in case  your initializing local databases.

Personally I have a settings table that I save my settings in:

local settings = {}

settings.firstRun = true

settings.loggedIn = false

Then I use the code and info in this tutorial to load and save the table:  https://coronalabs.com/blog/2014/10/14/tutorial-saving-and-loading-lua-tables-with-json/

Rob

Thanks Rob! Your tutorial was really easy to follow and implement! Regarding account creation, do you have any idea how companies/apps create an “account verification” through email or text message, where they send you a code and you are required to provide the code during the account creation process in order to verify your account?

And about password encryption, I’m a little confused about the openssl plugin. Would you suggest the encryption to be done in the app, before sending it over to the web server, or with a php script once the data has been received from the app?

Account verification emails would be generated by your server and sent to the person. In the email you would have link to a script on your webserver that has some code attached to the URL as a GET parameter:

https://yourserver.com/verifyaccount.php?verificationcode=SomebiglongBase64encodedhardToTypebyhandstring

Of course you would later decode that base64 encoded string and compare that value to a value  you’ve stored in your database for that user. If they match, you’ve got a good verification. Your mobile app isn’t involved in this part.

Password encryption, if you’re connecting to your script on an https: server, you wouldn’t necessarily need to encrypt it and your server script would do the one way encryption and compare with the already encrypted value in the database (checking a longing) or do the initial write with the one way encrypted password.

However, if you’re not going over https: and using http:, you need to encrypt it in your app. It doesn’t hurt even going over https that you encrypt it. On initial create, you could just store the value you received, but it might make more sense to apply your salt string and re-encrypt it.

Rob

Hey Rob,

I am now at a different phase of my app, and got all the logging in and account creation finished and working, password encryption and email verification included. I now would like to incorporate google maps into the app, and I’m now using the business sample app as guidance on how to implement the api. I was just curious though if it is possible to use the maps api to show location of other users using the app who are online, similar to how the ios Find My Friends app works or Uber does.

BTW, should I post this as a new topic?

Thanks in advance,

-YL

If you just want to drop pins where people are and annotate those pins, it’s possible. The Business App sample should show you how to do that. What it won’t show you is how to retrieve that data from your server.

Rob

I’m not sure I understand what you mean. By drop pins, did you mean do that in the code for preset locations?

Allow me to further explain what I would like to do with my app. Hypothetically, users would want to interact with each other, and should be able to see nearby users who choose to be discoverable for others (in real time), and maybe set meet up locations too. Is this possible with corona? If so, do you have any idea as to how this would be achieved or if it has been discussed before in the forums or with sample apps?

What I mean by drop pins (which is the map lingo) is to place a marker at the location where something you care about exists. The sample you are working from drops four custom pins (Starbucks Logos) at the location where there are Starbucks located around the Palo Alto area.

In the code (I’m going from memory as I don’t have it open in front of me) there is a table that contains the latitude and longitude for each of the locations and perhaps some other info. I believe I loop over that table with a for loop and instruct the map API’s to place the pin a the lat/long spot on the map.

What I don’t do is I don’t fetch that information from a server. To do what you want, you have to have a way for each app user to find the locations of the other. Typically that means your app will report your location to your server. Then you will have a way to talk to your server and get all people near you. That should return to you a list of people, their lat/long and other info. You can then plot those pins on your map in a way similar to the sample.

If you want more real time behavior you may need to implement a way to have your server send out push notifications that can update your app, or use a multi-player game plugin feature (check out Photon Cloud in our store.coronalabs.com as a starter). Your app could reasonably send out updates and Photon cloud would broadcast values back out to everyone in near real time.

Rob

Hey Rob,

I was wondering if you would be willing to chat? You’ve been helping me a lot with my app through these forums, but it would probably be easier if we could actually have a conversation on some other platform, assuming of course you are willing to do so. I just needed some more help with the maps API like I mentioned before, and I really don’t know where else to go for help.

Thanks in advance,

YL

My access is pretty much limited to here. Other community members might be more available to have a chat with you.

Hey Rob,

I’m pretty lost again. I’m still trying to make progress on my app but I can’t seem to find in depth help with what I want to do. Today I found about Parse server (which apparently is only going on for one more year) and some stuff like REST api which im not sure what they mean. Thing is, im considering again switching platforms because I cant find much help or places to learn how to implement these functionalities into my app… more specifically, being able to locate other users on a map and be able to send them a request (for a service) and then have the other user agree to the service or decline it.

Actually you’ve done something in your own thread called “Hijacking”. You did it twice actually. The first time was asking about activity indicators that have nothing to do with business app logins and passwords.

These are community forums which means that the community pitches in to help each other. They need good thread topics to respond to and generally they don’t response once a staff member has responded.  The second hijack came when you changed the topic to discuss maps and putting markers on the map and getting data from services.

There are lots of people willing to help answer these questions and there is also the “Google machine”. There is forum search. It’s amazing what can be found by doing:  “Corona map tutorial” in a google search.

I suggest that we close this thread unless it has to do with business app login and password encryption. Start a new thread asking the question you need help with at the moment. Make sure to create a good title, let people know what you’ve tried and what resources you’ve looked at and see what happens.

Rob

I decided to post to this thread because you were following it, and you clearly know corona very well, so I thought it would be my best option to talk to someone who I had already had contact with before and seemed to be active in the forums.

I’m well aware of the things that can be found by using google, which is the first thing I do when i try to work on something i’m not familiar with. Before I made any posts at all in this forum actually, I made sure to research the subject thoroughly and try to find all the information I could. The only reason I started posting on this forum, was because I was unable to find anything that could truly help me develop my app.

To your last suggestion, I already did, a few days ago. Again, I came back to this thread because the other one wasn’t getting much attention.

You can bump your post after say 24 hours or so if you’re not getting traffic. What was it called? or better yet what is the URL to the thread?