- This topic has 11 replies, 2 voices, and was last updated 12 years, 4 months ago by
nvts.
-
AuthorPosts
-
mugmonjMemberHow do you put a password on a app? I already tried to use the Password field but i could not figure it out.
April 5, 2013 at 12:20 pm #337608
nvtsMemberYou have to use JS code in your app_custon.js file.
Create a password field, then a button, attach the JS code to that button.
Here is sample code for hard coded password. I pull mine for a db for security reasons.
function accesspass()
{
var StoredAccessPass=”1234″;
var AccessPass=$(‘#m1-screen-passwordField1’).val();if (StoredAccessPass==AccessPass)
{
phoneui.gotoScreen(‘#m1-screen2’, phoneui.transitions.SlideLeft);
}
else
{
alert(‘Sorry, Wrong password’);
}
}Cheers…
April 5, 2013 at 1:57 pm #337620
mugmonjMemberSo this is the code that I linked to the button where do i input my password and the link to what I want to lock?
Thanks Jfunction accesspass()
{
var StoredAccessPass=”1234″;
var AccessPass=$(‘#m1-screen-passwordField1’).val();if (StoredAccessPass==AccessPass)
{
phoneui.gotoScreen(‘#m1-screen2’, phoneui.transitions.SlideLeft);
}
else
{
alert(‘Sorry, Wrong password’);
}
}April 5, 2013 at 2:09 pm #337622
nvtsMemberYou need to create 2 screens. The first screen will have the password textarea and a button.
Then that button will call the js script in you app_custom.js file with the accesspass(); in the run javascript
If there in no fields created on the second screen you will need to add that screen to the additional project files under the first screen.
The when you run the app you will enter the password and press the button and it correct it will go to the second screen and it it is wrong, it will show the alert message.
Cheers…
April 5, 2013 at 2:22 pm #337625
mugmonjMemberWhat do you have to change in the script for the button to make it work properly?
Thank You JApril 5, 2013 at 3:02 pm #337627
nvtsMemberYou have to go to the actions for the button and select run javascript and place the function call that was posted above to run when clicked.
Cheers…
Edited:
I added a zip file that has a password & landing screen. Look at the button action on the password screen and look at the password_custom.js file for the accesspass() function.
Attachments:
You must be logged in to view attached files.April 5, 2013 at 3:27 pm #337629
mugmonjMemberthis is what i’ve done view link and it still says error
April 5, 2013 at 3:43 pm #337631
nvtsMemberYours has a lot of missing items. It was just my example you needed to change screen and screen2 to your .mobi name like login for screen.
Did you download mine and try. It should run fine as i tested before zipping.
Cheers…
April 5, 2013 at 3:50 pm #337632
mugmonjMemberThank You Works Great!!
Thank You JApril 5, 2013 at 3:57 pm #337633
nvtsMemberYour welcome.
I always put my javascript into the appname_custom.js file and then call it when needed as a function, like the button.
Cheers…
April 5, 2013 at 3:59 pm #337634
mugmonjMemberHow do I change Password From 1234 to something else?
April 5, 2013 at 4:08 pm #337635
nvtsMemberIt is hard coded in the password_custom.js file in the folder password-www. I edit with a editor. You can edit it through Mobione Test Center while running the app under tools/view source then select the password_custom.js file.
Change var StoredAccessPass=”1234″;
Save and reload.
This is not very secure way of having a password. That is why I use a db to store my passwords as other data needed for my apps.
Cheers…
-
AuthorPosts