Advertisement
Guest User

Untitled

a guest
Aug 8th, 2017
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.96 KB | None | 0 0
  1.  
  2. /*
  3. Create window for IP/hostname, username and password
  4. */
  5. var logInWin = Titanium.UI.createWindow({
  6. title: 'Elvenite Search Application',
  7. backgroundImage:'loginbgimg.png'
  8. });
  9.  
  10. //IP textfield
  11. var ip = Titanium.UI.createTextField({
  12. top:50,
  13. height:40,
  14. width:300,
  15. hintText:'IP/Hostname'});
  16. //clearOnEdit:true
  17.  
  18. //Username textfield
  19. var username = Titanium.UI.createTextField({
  20. top:100,
  21. height:40,
  22. width:300,
  23. hintText:'Username'});
  24. //clearOnEdit:true
  25.  
  26. //Password textfield
  27. var password = Titanium.UI.createTextField({
  28. top:150,
  29. height:40,
  30. width:300,
  31. hintText:'Password',
  32. autocorrect:false,
  33. passwordMask:true});
  34. //clearOnEdit:true
  35.  
  36. //Login button
  37. var login = Titanium.UI.createButton({
  38. top:200,
  39. height:40,
  40. width:300,
  41. title:'Login'});
  42.  
  43. //Load button
  44. var load = Titanium.UI.createButton({
  45. top:250,
  46. height:40,
  47. width:300,
  48. title:'Load Last Login'});
  49.  
  50. //Create menu
  51. var activity = Ti.Android.currentActivity;
  52. activity.onCreateOptionsMenu = function(e) {
  53.  
  54. var menu = e.menu;
  55. //Back
  56. var menuItem = menu.add({title: "Back" });
  57. menuItem.addEventListener("click", function() {
  58. Ti.Android.currentActivity.finish();
  59. });
  60. };
  61.  
  62. //Add elements to log in window
  63. logInWin.add(ip);
  64. logInWin.add(username);
  65. logInWin.add(password);
  66. logInWin.add(login);
  67. logInWin.add(load);
  68. logInWin.open({});
  69.  
  70. var encryption_key = 65962127;
  71.  
  72. /*
  73. Intents
  74. */
  75. var intent = Ti.Android.createIntent({
  76. action: Ti.Android.ACTION_MAIN,
  77. url:'ui/searchWin.js'});
  78.  
  79.  
  80. /*
  81. Listeners
  82. */
  83.  
  84. //Login button listener
  85. login.addEventListener('click', function(){
  86.  
  87. if((ip.value == undefined) || (username.value == undefined) || (password.value == undefined)
  88. ||(ip.value == "") || (username.value == "") || (password.value == "")){
  89. Titanium.UI.createAlertDialog({
  90. title:'Login Fields',
  91. message:'You must fill in a value in all fields'}).show();
  92. }else{
  93. var hostname = ip.value;
  94. var name = username.value;
  95. var pw = password.value;
  96.  
  97. var w = Titanium.Filesystem.getFile(Titanium.Filesystem.applicationDataDirectory, 'logFile.txt');
  98. Ti.API.info('Path to logDir: ' + w.nativePath);
  99. var temp1 = (hostname + ' ' + name + ' ' + pw).toString();
  100. w.write(encrypt(temp1));
  101. Titanium.API.info("Contents of the file = " + encrypt(temp1));
  102.  
  103. //TODO: SEND INFO TO SERVER??
  104.  
  105. intent.addCategory(Ti.Android.CATEGORY_LAUNCHER);
  106. Ti.Android.currentActivity.startActivity(intent);}
  107.  
  108. });
  109.  
  110. //Load button listener
  111. load.addEventListener('click', function(){
  112.  
  113. var r = Titanium.Filesystem.getFile(Titanium.Filesystem.applicationDataDirectory, 'logFile.txt');
  114. if(r.exists()){
  115. var contents = r.read();
  116. var temp2 = decrypt(contents);
  117. var contentsAr = temp2.split(/\s/g); //Split the data in 3 parts ip,username,password.
  118. // dynamically set value for the log in fields
  119. ip.value = contentsAr[0];
  120. username.value = contentsAr[1];
  121. password.value = contentsAr[2];
  122. Titanium.API.info("Contents of the file = "+contentsAr[0]+' '+contentsAr[1]+' '+contentsAr[2]);
  123. }else{
  124. Titanium.UI.createAlertDialog({
  125. title:'Previous Login',
  126. message:'No previous login has been stored'}).show();}
  127.  
  128. });
  129.  
  130.  
  131. function encrypt (textstring)
  132. {
  133. var encrypted_string = ""
  134. for(var i=0;i<textstring.length;i++)
  135. encrypted_string += (String.fromCharCode(textstring.charCodeAt(i)^encryption_key))
  136. return encrypted_string
  137. }
  138.  
  139. function decrypt (encrypted_string)
  140. {
  141. var decrypted_string = ""
  142. for(var i=0;i<encrypted_string.toString().length;i++)
  143. decrypted_string += (String.fromCharCode(encrypted_string.toString().charCodeAt(i)^encryption_key))
  144. return decrypted_string.toString();
  145. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement