Guest User

Untitled

a guest
May 26th, 2018
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import QtQuick 1.1
  2. import com.nokia.meego 1.0
  3.  
  4. Page {
  5.     id: mainPage
  6.     tools: toolsBar
  7.  
  8.     Image {
  9.         id: passwdGenIcon
  10.         source: 'qrc:/images/KhtPasswdGenLock.svg'
  11.         anchors.top: parent.top
  12.         anchors.topMargin: 10
  13.         anchors.horizontalCenter: parent.horizontalCenter
  14.         height: 80
  15.         width: 80
  16.     }
  17.  
  18.     Label {
  19.         id: masterPasswordLabel
  20.         text: qsTr("Master Password")
  21.         anchors.top: passwdGenIcon.bottom
  22.         anchors.left: parent.left
  23.         anchors.right: parent.right
  24.         anchors.rightMargin: 10
  25.         anchors.leftMargin: 10
  26.         anchors.topMargin: 10
  27.     }
  28.  
  29.     TextField {
  30.         id: masterPasswordField
  31.         placeholderText: qsTr("Master Password")
  32.         anchors.top: masterPasswordLabel.bottom
  33.         anchors.left: masterPasswordLabel.left
  34.         anchors.right: parent.right
  35.         anchors.rightMargin: 10
  36.         anchors.topMargin: 10
  37.         echoMode: TextInput.Password
  38.         onTextChanged:{generate()}
  39.     }
  40.  
  41.     Label {
  42.         id: domainLabel
  43.         text: qsTr("Domain Name or Text")
  44.         anchors.top: masterPasswordField.bottom
  45.         anchors.left: parent.left
  46.         anchors.leftMargin: 10
  47.         anchors.right: parent.right
  48.         anchors.rightMargin: 10
  49.         anchors.topMargin: 10
  50.     }
  51.  
  52.     TextField {
  53.         id: domainField
  54.         anchors.top: domainLabel.bottom
  55.         placeholderText: qsTr("Ex : google.com")
  56.         anchors.left: domainLabel.left
  57.         anchors.right: parent.right
  58.         anchors.rightMargin: 10
  59.         anchors.topMargin: 10
  60.         onTextChanged:{generate()}
  61.  
  62.     }
  63.  
  64.     Label {
  65.         id: passwordLabel
  66.         text: qsTr("Generated Password")
  67.         anchors.topMargin: 40
  68.         anchors.top: domainField.bottom
  69.         anchors.left: parent.left
  70.         anchors.leftMargin: 10
  71.         anchors.right: parent.right
  72.         anchors.rightMargin: 10
  73.     }
  74.  
  75.  
  76.     TextField  {
  77.         id: passwordField
  78.         //color: "red"
  79.         text: ""
  80.         placeholderText: qsTr("Result")
  81.         anchors.top: passwordLabel.bottom
  82.         anchors.topMargin: 10
  83.         anchors.left: passwordLabel.left
  84.         anchors.right: parent.right
  85.         anchors.rightMargin: 10
  86.         visible: true
  87.         readOnly: true
  88.     }
  89.  
  90.  
  91.     Button  {
  92.         id: copyButton
  93.         text: qsTr("Copy to Clipboard")
  94.         anchors.top: passwordField.bottom
  95.         anchors.topMargin: 30
  96.         anchors.horizontalCenter: parent.horizontalCenter
  97.         visible: true
  98.         onClicked: {passwordField.selectAll();passwordField.copy();}
  99.     }
  100.  
  101.  
  102.     /*states: [
  103.         State {
  104.             name: "portraitLayout"
  105.             when: mainPage.inPortrait
  106.             AnchorChanges {
  107.                 target: masterPasswordField
  108.                 anchors.top: passwordLabel.bottom
  109.                 anchors.left: passwordLabel.left
  110.                 anchors.right: parent.right
  111.             }
  112.             AnchorChanges {
  113.                 target: domainField
  114.                 anchors.top: domainLabel.bottom
  115.                 anchors.left: domainLabel.left
  116.                 anchors.right: parent.right
  117.             }
  118.  
  119.  
  120.         },
  121.  
  122.         State {
  123.             name: "landscapeLayout"
  124.             when: !mainPage.inPortrait
  125.             AnchorChanges {
  126.                 target: masterPasswordField
  127.                 anchors.top: passwordLabel.top
  128.                 anchors.left: parent.left
  129.                 anchors.right: parent.right
  130.             }
  131.             AnchorChanges {
  132.                 target: domainField
  133.                 anchors.top: domainLabel.bottom
  134.                 anchors.left: domainLabel.left
  135.                 anchors.right: parent.right
  136.  
  137.             }
  138.  
  139.  
  140.         }
  141.     ]*/
  142.  
  143.     transitions: Transition {
  144.         // smoothly reanchor between layouts
  145.         AnchorAnimation { duration: 1000; easing.type: Easing.OutBounce }
  146.     }
  147.  
  148.     ToolBarLayout {
  149.         id: toolsBar
  150.         visible: true
  151.  
  152.         ToolIcon { platformIconId: "toolbar-view-menu";
  153.             anchors.right: parent===undefined ? undefined : parent.right;
  154.             onClicked: (mainMenu.status == DialogStatus.Closed) ? mainMenu.open() : mainMenu.close();
  155.         }
  156.     }
  157.  
  158.  
  159.  
  160.     function generate() {
  161.         var base16Key = "0123456789abcdef";
  162.         var base64Key = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789$#";
  163.  
  164.         if ((masterPasswordField.text == '') || (domainField.text == '')) {
  165.             passwordField.text = '';
  166.             return;
  167.         }
  168.  
  169.         var md5Pass = Qt.md5(masterPasswordField.text+':'+domainField.text);
  170.         var shortenedPass = "";
  171.  
  172.         for (var index=0;index<=31;index=index+4){
  173.             shortenedPass = shortenedPass + base64Key.charAt(
  174.                         ((base16Key.indexOf(md5Pass.charAt(index))+1)
  175.                          + (base16Key.indexOf(md5Pass.charAt(index+1))+1)
  176.                          + (base16Key.indexOf(md5Pass.charAt(index+2))+1)
  177.                          + (base16Key.indexOf(md5Pass.charAt(index+3))+1)-1))
  178.         }
  179.  
  180.  
  181.         //Force for always having a number
  182.         if (!(/\d/.test(shortenedPass))) {
  183.             if (/e/.test(shortenedPass)) {
  184.                 shortenedPass = shortenedPass.replace('e','3');
  185.             } else if (/o/.test(shortenedPass)) {
  186.                 shortenedPass = shortenedPass.replace('o','0');
  187.             } else if (/t/.test(shortenedPass)) {
  188.                 shortenedPass = shortenedPass.replace('t','4');
  189.             } else if (/i/.test(shortenedPass)) {
  190.                 shortenedPass = shortenedPass.replace('i','1');
  191.             } else if (/z/.test(shortenedPass)) {
  192.                 shortenedPass = shortenedPass.replace('z','2');
  193.             } else {
  194.                 shortenedPass = shortenedPass.substr(0, 7) +  base64Key.indexOf(shortenedPass.charAt(7)).toString()[0];
  195.  
  196.             }
  197.         }
  198.  
  199.         passwordField.text = shortenedPass;
  200.  
  201.     }
  202. }
Add Comment
Please, Sign In to add comment