Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import QtQuick 1.1
- import com.nokia.meego 1.0
- Page {
- id: mainPage
- tools: toolsBar
- Image {
- id: passwdGenIcon
- source: 'qrc:/images/KhtPasswdGenLock.svg'
- anchors.top: parent.top
- anchors.topMargin: 10
- anchors.horizontalCenter: parent.horizontalCenter
- height: 80
- width: 80
- }
- Label {
- id: masterPasswordLabel
- text: qsTr("Master Password")
- anchors.top: passwdGenIcon.bottom
- anchors.left: parent.left
- anchors.right: parent.right
- anchors.rightMargin: 10
- anchors.leftMargin: 10
- anchors.topMargin: 10
- }
- TextField {
- id: masterPasswordField
- placeholderText: qsTr("Master Password")
- anchors.top: masterPasswordLabel.bottom
- anchors.left: masterPasswordLabel.left
- anchors.right: parent.right
- anchors.rightMargin: 10
- anchors.topMargin: 10
- echoMode: TextInput.Password
- onTextChanged:{generate()}
- }
- Label {
- id: domainLabel
- text: qsTr("Domain Name or Text")
- anchors.top: masterPasswordField.bottom
- anchors.left: parent.left
- anchors.leftMargin: 10
- anchors.right: parent.right
- anchors.rightMargin: 10
- anchors.topMargin: 10
- }
- TextField {
- id: domainField
- anchors.top: domainLabel.bottom
- placeholderText: qsTr("Ex : google.com")
- anchors.left: domainLabel.left
- anchors.right: parent.right
- anchors.rightMargin: 10
- anchors.topMargin: 10
- onTextChanged:{generate()}
- }
- Label {
- id: passwordLabel
- text: qsTr("Generated Password")
- anchors.topMargin: 40
- anchors.top: domainField.bottom
- anchors.left: parent.left
- anchors.leftMargin: 10
- anchors.right: parent.right
- anchors.rightMargin: 10
- }
- TextField {
- id: passwordField
- //color: "red"
- text: ""
- placeholderText: qsTr("Result")
- anchors.top: passwordLabel.bottom
- anchors.topMargin: 10
- anchors.left: passwordLabel.left
- anchors.right: parent.right
- anchors.rightMargin: 10
- visible: true
- readOnly: true
- }
- Button {
- id: copyButton
- text: qsTr("Copy to Clipboard")
- anchors.top: passwordField.bottom
- anchors.topMargin: 30
- anchors.horizontalCenter: parent.horizontalCenter
- visible: true
- onClicked: {passwordField.selectAll();passwordField.copy();}
- }
- /*states: [
- State {
- name: "portraitLayout"
- when: mainPage.inPortrait
- AnchorChanges {
- target: masterPasswordField
- anchors.top: passwordLabel.bottom
- anchors.left: passwordLabel.left
- anchors.right: parent.right
- }
- AnchorChanges {
- target: domainField
- anchors.top: domainLabel.bottom
- anchors.left: domainLabel.left
- anchors.right: parent.right
- }
- },
- State {
- name: "landscapeLayout"
- when: !mainPage.inPortrait
- AnchorChanges {
- target: masterPasswordField
- anchors.top: passwordLabel.top
- anchors.left: parent.left
- anchors.right: parent.right
- }
- AnchorChanges {
- target: domainField
- anchors.top: domainLabel.bottom
- anchors.left: domainLabel.left
- anchors.right: parent.right
- }
- }
- ]*/
- transitions: Transition {
- // smoothly reanchor between layouts
- AnchorAnimation { duration: 1000; easing.type: Easing.OutBounce }
- }
- ToolBarLayout {
- id: toolsBar
- visible: true
- ToolIcon { platformIconId: "toolbar-view-menu";
- anchors.right: parent===undefined ? undefined : parent.right;
- onClicked: (mainMenu.status == DialogStatus.Closed) ? mainMenu.open() : mainMenu.close();
- }
- }
- function generate() {
- var base16Key = "0123456789abcdef";
- var base64Key = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789$#";
- if ((masterPasswordField.text == '') || (domainField.text == '')) {
- passwordField.text = '';
- return;
- }
- var md5Pass = Qt.md5(masterPasswordField.text+':'+domainField.text);
- var shortenedPass = "";
- for (var index=0;index<=31;index=index+4){
- shortenedPass = shortenedPass + base64Key.charAt(
- ((base16Key.indexOf(md5Pass.charAt(index))+1)
- + (base16Key.indexOf(md5Pass.charAt(index+1))+1)
- + (base16Key.indexOf(md5Pass.charAt(index+2))+1)
- + (base16Key.indexOf(md5Pass.charAt(index+3))+1)-1))
- }
- //Force for always having a number
- if (!(/\d/.test(shortenedPass))) {
- if (/e/.test(shortenedPass)) {
- shortenedPass = shortenedPass.replace('e','3');
- } else if (/o/.test(shortenedPass)) {
- shortenedPass = shortenedPass.replace('o','0');
- } else if (/t/.test(shortenedPass)) {
- shortenedPass = shortenedPass.replace('t','4');
- } else if (/i/.test(shortenedPass)) {
- shortenedPass = shortenedPass.replace('i','1');
- } else if (/z/.test(shortenedPass)) {
- shortenedPass = shortenedPass.replace('z','2');
- } else {
- shortenedPass = shortenedPass.substr(0, 7) + base64Key.indexOf(shortenedPass.charAt(7)).toString()[0];
- }
- }
- passwordField.text = shortenedPass;
- }
- }
Add Comment
Please, Sign In to add comment