-
Notifications
You must be signed in to change notification settings - Fork 511
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
234 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
INCLUDEPATH += \ | ||
$$PWD/cpp/ | ||
|
||
HEADERS += \ | ||
$$PWD/cpp/RandomPassword.h | ||
|
||
SOURCES += \ | ||
$$PWD/cpp/RandomPassword.cpp | ||
|
||
RESOURCES += \ | ||
$$PWD/qml/RandomPassword.qrc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
#include "RandomPassword.h" | ||
|
||
// Qt lib import | ||
#include <QClipboard> | ||
#include <QApplication> | ||
#include <QDateTime> | ||
|
||
// JQToolsLibrary import | ||
#include "JQToolsLibrary.hpp" | ||
|
||
using namespace RandomPassword; | ||
|
||
Manage::Manage() | ||
{ | ||
srand( QDateTime::currentDateTime().toTime_t() ); | ||
} | ||
|
||
QString Manage::randomPassword(const int &length, const bool &number, const bool &englishCharacters, const bool &caseSensitive, const bool &dividingLine) | ||
{ | ||
QString password; | ||
QString table; | ||
|
||
auto numberTable = "0123456789"; | ||
auto lowercaseCharacters = "abcdefghijklmnopqrstuvwxyz"; | ||
auto upperCharacters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; | ||
|
||
if ( number ) | ||
{ | ||
table += numberTable; | ||
} | ||
if ( englishCharacters ) | ||
{ | ||
if ( caseSensitive ) | ||
{ | ||
table += lowercaseCharacters; | ||
table += upperCharacters; | ||
} | ||
else | ||
{ | ||
table += lowercaseCharacters; | ||
} | ||
} | ||
|
||
if ( table.isEmpty() ) { return { }; } | ||
|
||
for ( auto index = 0; index < length; index++ ) | ||
{ | ||
if ( dividingLine && ! ( (index + 1) % 4 ) ) | ||
{ | ||
password += '-'; | ||
} | ||
else | ||
{ | ||
password += table.at( rand() % table.size() ); | ||
} | ||
} | ||
|
||
return password; | ||
} | ||
|
||
void Manage::setClipboardText(const QString &string) | ||
{ | ||
qApp->clipboard()->setText( string ); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
#ifndef __RandomPassword_h__ | ||
#define __RandomPassword_h__ | ||
|
||
// Qt lib import | ||
#include <QObject> | ||
|
||
#define RANDOMPASSWORD_INITIALIZA \ | ||
{ \ | ||
qmlRegisterType<RandomPassword::Manage>("RandomPassword", 1, 0, "RandomPasswordManage"); \ | ||
} | ||
|
||
namespace RandomPassword | ||
{ | ||
|
||
class Manage: public QObject | ||
{ | ||
Q_OBJECT | ||
Q_DISABLE_COPY(Manage) | ||
|
||
public: | ||
Manage(); | ||
|
||
~Manage() = default; | ||
|
||
public slots: | ||
QString randomPassword(const int &length, const bool &number, const bool &englishCharacters, const bool &caseSensitive, const bool &dividingLine); | ||
|
||
void setClipboardText(const QString &string); | ||
}; | ||
|
||
} | ||
|
||
#endif//__RandomPassword_h__ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
import QtQuick 2.5 | ||
import QtQuick.Controls 1.4 | ||
import QtGraphicalEffects 1.0 | ||
import "qrc:/MaterialUI/Interface/" | ||
import RandomPassword 1.0 | ||
|
||
Item { | ||
id: randomPassword | ||
width: 620 | ||
height: 540 | ||
|
||
property bool changingFlag: true | ||
|
||
Component.onCompleted: { | ||
changingFlag = false; | ||
} | ||
|
||
RandomPasswordManage { | ||
id: randomPasswordManage | ||
} | ||
|
||
Item { | ||
anchors.centerIn: parent | ||
width: 620 | ||
height: 540 | ||
|
||
MaterialLabel { | ||
x: 40 | ||
y: 132 | ||
text: "密码长度:" | ||
} | ||
|
||
MaterialTextField { | ||
id: textFieldForLength | ||
x: 116 | ||
y: 91 | ||
width: 50 | ||
characterLimit: 2 | ||
characterLimitVisible: false | ||
validator: RegExpValidator{ regExp: /^([0-9]+)$/ } | ||
text: "15" | ||
} | ||
|
||
MaterialTextField { | ||
id: textFieldForPassword | ||
x: 40 | ||
y: 317 | ||
width: 540 | ||
placeholderText: "随机密码" | ||
} | ||
|
||
MaterialCheckBox { | ||
id: checkBoxForNumber | ||
x: 34 | ||
y: 181 | ||
text: "允许数字" | ||
checked: true | ||
} | ||
|
||
MaterialCheckBox { | ||
id: checkBoxForEnglishCharacters | ||
x: 154 | ||
y: 181 | ||
text: "允许英文字符" | ||
checked: true | ||
} | ||
|
||
MaterialCheckBox { | ||
id: checkBoxForCaseSensitive | ||
x: 302 | ||
y: 181 | ||
text: "区分大小写" | ||
checked: true | ||
enabled: checkBoxForEnglishCharacters.checked | ||
} | ||
|
||
MaterialCheckBox { | ||
id: checkBoxForDividingLine | ||
x: 436 | ||
y: 181 | ||
text: "插入分割线" | ||
checked: true | ||
} | ||
|
||
MaterialButton { | ||
x: 40 | ||
y: 259 | ||
width: 120 | ||
text: "随机密码" | ||
|
||
onClicked: { | ||
textFieldForPassword.text = randomPasswordManage.randomPassword( | ||
parseInt( textFieldForLength.text ), | ||
checkBoxForNumber.checked, | ||
checkBoxForEnglishCharacters.checked, | ||
checkBoxForCaseSensitive.checked, | ||
checkBoxForDividingLine.checked | ||
); | ||
materialUI.showSnackbarMessage( "随机密码已经生成" ); | ||
} | ||
} | ||
|
||
MaterialButton { | ||
x: 166 | ||
y: 259 | ||
width: 120 | ||
text: "复制到剪切板" | ||
|
||
onClicked: { | ||
randomPasswordManage.setClipboardText( textFieldForPassword.text ); | ||
materialUI.showSnackbarMessage( "URL已经复制到了剪切板" ); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<RCC> | ||
<qresource prefix="/RandomPassword"> | ||
<file>RandomPassword.qml</file> | ||
</qresource> | ||
</RCC> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
include($$PWD/Utf16Transform/Utf16Transform.pri) | ||
include($$PWD/RgbStringTransform/RgbStringTransform.pri) | ||
include($$PWD/UrlEncode/UrlEncode.pri) | ||
include($$PWD/RandomPassword/RandomPassword.pri) | ||
include($$PWD/CaseTransform/CaseTransform.pri) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
#ifndef __JQToolsLibrary_hpp__ | ||
#define __JQToolsLibrary_hpp__ | ||
|
||
#define JQTOOLS_VERSIONSTRING "16.5.27" | ||
#define JQTOOLS_VERSIONSTRING "16.5.30" | ||
|
||
#endif//__JQToolsLibrary_hpp__ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters