Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Create window for IP/hostname, username and password
- */
- var logInWin = Titanium.UI.createWindow({
- title: 'Elvenite Search Application',
- backgroundImage:'loginbgimg.png'
- });
- //IP textfield
- var ip = Titanium.UI.createTextField({
- top:50,
- height:40,
- width:300,
- hintText:'IP/Hostname'});
- //clearOnEdit:true
- //Username textfield
- var username = Titanium.UI.createTextField({
- top:100,
- height:40,
- width:300,
- hintText:'Username'});
- //clearOnEdit:true
- //Password textfield
- var password = Titanium.UI.createTextField({
- top:150,
- height:40,
- width:300,
- hintText:'Password',
- autocorrect:false,
- passwordMask:true});
- //clearOnEdit:true
- //Login button
- var login = Titanium.UI.createButton({
- top:200,
- height:40,
- width:300,
- title:'Login'});
- //Load button
- var load = Titanium.UI.createButton({
- top:250,
- height:40,
- width:300,
- title:'Load Last Login'});
- //Create menu
- var activity = Ti.Android.currentActivity;
- activity.onCreateOptionsMenu = function(e) {
- var menu = e.menu;
- //Back
- var menuItem = menu.add({title: "Back" });
- menuItem.addEventListener("click", function() {
- Ti.Android.currentActivity.finish();
- });
- };
- //Add elements to log in window
- logInWin.add(ip);
- logInWin.add(username);
- logInWin.add(password);
- logInWin.add(login);
- logInWin.add(load);
- logInWin.open({});
- var encryption_key = 65962127;
- /*
- Intents
- */
- var intent = Ti.Android.createIntent({
- action: Ti.Android.ACTION_MAIN,
- url:'ui/searchWin.js'});
- /*
- Listeners
- */
- //Login button listener
- login.addEventListener('click', function(){
- if((ip.value == undefined) || (username.value == undefined) || (password.value == undefined)
- ||(ip.value == "") || (username.value == "") || (password.value == "")){
- Titanium.UI.createAlertDialog({
- title:'Login Fields',
- message:'You must fill in a value in all fields'}).show();
- }else{
- var hostname = ip.value;
- var name = username.value;
- var pw = password.value;
- var w = Titanium.Filesystem.getFile(Titanium.Filesystem.applicationDataDirectory, 'logFile.txt');
- Ti.API.info('Path to logDir: ' + w.nativePath);
- var temp1 = (hostname + ' ' + name + ' ' + pw).toString();
- w.write(encrypt(temp1));
- Titanium.API.info("Contents of the file = " + encrypt(temp1));
- //TODO: SEND INFO TO SERVER??
- intent.addCategory(Ti.Android.CATEGORY_LAUNCHER);
- Ti.Android.currentActivity.startActivity(intent);}
- });
- //Load button listener
- load.addEventListener('click', function(){
- var r = Titanium.Filesystem.getFile(Titanium.Filesystem.applicationDataDirectory, 'logFile.txt');
- if(r.exists()){
- var contents = r.read();
- var temp2 = decrypt(contents);
- var contentsAr = temp2.split(/\s/g); //Split the data in 3 parts ip,username,password.
- // dynamically set value for the log in fields
- ip.value = contentsAr[0];
- username.value = contentsAr[1];
- password.value = contentsAr[2];
- Titanium.API.info("Contents of the file = "+contentsAr[0]+' '+contentsAr[1]+' '+contentsAr[2]);
- }else{
- Titanium.UI.createAlertDialog({
- title:'Previous Login',
- message:'No previous login has been stored'}).show();}
- });
- function encrypt (textstring)
- {
- var encrypted_string = ""
- for(var i=0;i<textstring.length;i++)
- encrypted_string += (String.fromCharCode(textstring.charCodeAt(i)^encryption_key))
- return encrypted_string
- }
- function decrypt (encrypted_string)
- {
- var decrypted_string = ""
- for(var i=0;i<encrypted_string.toString().length;i++)
- decrypted_string += (String.fromCharCode(encrypted_string.toString().charCodeAt(i)^encryption_key))
- return decrypted_string.toString();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement