Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
F
fmp_home
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
zhenfei.zhang
fmp_home
Commits
f0e1ed5f
Commit
f0e1ed5f
authored
Apr 28, 2017
by
NitefullWind
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
1. 实现密码加密保存。 2. 增加弹出信息框。
parent
beca7d07
Show whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
585 additions
and
7 deletions
+585
-7
algorithm.h
+39
-0
fmp_home.pro
+7
-3
fmp_home_settings.cpp
+10
-0
fmp_home_settings.h
+8
-0
fmp_login.cpp
+77
-3
fmp_login.h
+4
-0
fmp_login.ui
+20
-1
fmp_message.cpp
+56
-0
fmp_message.h
+36
-0
fmp_message.ui
+328
-0
No files found.
algorithm.h
0 → 100644
View file @
f0e1ed5f
#
ifndef
ALGORITHM_H
#define ALGORITHM_H
#include <QCryptographicHash>
#include <QByteArray>
#include <QDateTime>
// md5字符串分段点
const
qint8
pwd
[]
=
{
0
,
5
,
7
,
13
,
21
,
32
};
QByteArray
encrypt
(
const
QByteArray
&
plaintext
)
{
QByteArray
md5
=
QCryptographicHash
::
hash
(
QByteArray
::
number
(
QDateTime
::
currentMSecsSinceEpoch
()),
QCryptographicHash
::
Md5
).
toHex
();
QByteArray
base64
=
plaintext
.
toBase64
();
int
group
=
base64
.
length
()
/
4
;
QByteArray
cipertext
=
""
;
for
(
int
i
=
0
;
i
<
5
;
i
++
)
{
cipertext
+=
md5
.
mid
(
pwd
[
i
],
pwd
[
i
+
1
]
-
pwd
[
i
]);
cipertext
+=
base64
.
mid
(
i
*
group
,
group
);
}
return
cipertext
;
}
QByteArray
decrypt
(
const
QByteArray
&
ciphertext
)
{
int
group
=
(
ciphertext
.
length
()
-
(
pwd
[
5
]
-
pwd
[
0
]))
/
4
;
QByteArray
base64
=
""
;
for
(
int
i
=
0
;
i
<
5
;
i
++
)
{
base64
+=
ciphertext
.
mid
(
pwd
[
i
+
1
]
-
pwd
[
0
]
+
i
*
group
,
group
);
}
QByteArray
plaintext
=
QByteArray
::
fromBase64
(
base64
);
return
plaintext
;
}
#endif // ALGORITHM_H
fmp_home.pro
View file @
f0e1ed5f
...
...
@@ -23,7 +23,8 @@ SOURCES +=\
fmp_he_handlers
.
cpp
\
fmnumpad
.
cpp
\
fmp_home_settings
.
cpp
\
fmp_flicker
.
cpp
fmp_flicker
.
cpp
\
fmp_message
.
cpp
HEADERS
+=
fmp_home
.
h
\
fmp_home_plugin_p
.
h
\
...
...
@@ -37,12 +38,15 @@ HEADERS += fmp_home.h \
fmp_he_handlers
.
h
\
fmnumpad
.
h
\
fmp_home_settings
.
h
\
fmp_flicker
.
h
fmp_flicker
.
h
\
algorithm
.
h
\
fmp_message
.
h
FORMS
+=
\
fmp_home_navwindow
.
ui
\
fmp_login
.
ui
\
fmnumpad
.
ui
fmnumpad
.
ui
\
fmp_message
.
ui
unix
{
target
.
path
=
/
usr
/
lib
...
...
fmp_home_settings.cpp
View file @
f0e1ed5f
...
...
@@ -60,6 +60,16 @@ QString FMPHomeSettings::getStroeId()
return
_GetValue
(
FMP_INIKEY_LOGINSTOREID
).
toString
();
}
bool
FMPHomeSettings
::
getIsRememberPwd
()
{
return
_GetValue
(
FMP_INIKEY_REMEMBERPWD
,
false
).
toBool
();
}
bool
FMPHomeSettings
::
setIsRememberPwd
(
bool
isRemember
)
{
return
_SetValue
(
FMP_INIKEY_REMEMBERPWD
,
isRemember
);
}
QVariant
FMPHomeSettings
::
_GetValue
(
const
QString
&
key
,
QVariant
defaultValue
)
{
if
(
_settings
)
{
...
...
fmp_home_settings.h
View file @
f0e1ed5f
...
...
@@ -51,6 +51,14 @@ public:
*/
QString
getStroeId
();
/**
* @brief getIsRememberPwd setIsRememberPwd
* 获取/设置是否记住登录密码
* @return
*/
bool
getIsRememberPwd
();
bool
setIsRememberPwd
(
bool
isRemember
);
private
:
explicit
FMPHomeSettings
(
QObject
*
parent
=
0
);
...
...
fmp_login.cpp
View file @
f0e1ed5f
#
include
"fmp_login.h"
#include "ui_fmp_login.h"
#include "algorithm.h"
#include "fmp_home_settings.h"
#include
<QMessageBox>
#include
"fmp_message.h"
#include <QDesktopWidget>
#include <QJsonDocument>
#include <QJsonObject>
#include <QJsonParseError>
#include <QProcess>
#include <QFile>
#include "fmnetwork.h"
#include <QDebug>
...
...
@@ -28,6 +31,14 @@ FMPLogin::FMPLogin(QDialog *parent) :
_url
=
FMPHomeSettings
::
instance
()
->
getServer
();
_storeId
=
FMPHomeSettings
::
instance
()
->
getStroeId
();
_partnerId
=
FMPHomeSettings
::
instance
()
->
getPartnerId
();
if
(
FMPHomeSettings
::
instance
()
->
getIsRememberPwd
())
{
QString
userName
,
password
;
readPassword
(
userName
,
password
);
ui
->
user_edit
->
setText
(
userName
);
ui
->
pwd_edit
->
setText
(
password
);
ui
->
remember_check
->
setChecked
(
true
);
}
}
FMPLogin
::~
FMPLogin
()
...
...
@@ -37,12 +48,22 @@ FMPLogin::~FMPLogin()
void
FMPLogin
::
on_login_btn_clicked
()
{
if
(
ui
->
user_edit
->
text
().
isEmpty
())
{
FMPMessage
::
critical
(
this
,
QString
::
fromLocal8Bit
(
"账号不能为空"
));
ui
->
user_edit
->
setFocus
();
return
;
}
else
if
(
ui
->
pwd_edit
->
text
().
isEmpty
())
{
FMPMessage
::
critical
(
this
,
QString
::
fromLocal8Bit
(
"密码不能为空"
));
ui
->
pwd_edit
->
setFocus
();
return
;
}
this
->
setEnabled
(
false
);
if
(
login
(
ui
->
user_edit
->
text
(),
ui
->
pwd_edit
->
text
()))
{
this
->
close
();
}
else
{
QMessageBox
::
critical
(
this
,
"Login Failed"
,
_errorMsg
);
FMPMessage
::
critical
(
this
,
_errorMsg
);
this
->
setEnabled
(
true
);
ui
->
pwd_edit
->
clear
();
ui
->
pwd_edit
->
setFocus
();
...
...
@@ -75,7 +96,17 @@ bool FMPLogin::login(QString userName, QString password)
_errorMsg
=
error
.
errorString
();
}
}
return
isLogined
();
if
(
isLogined
())
{
if
(
ui
->
remember_check
->
isChecked
())
{
FMPHomeSettings
::
instance
()
->
setIsRememberPwd
(
true
);
savePassword
(
userName
,
password
);
}
else
{
FMPHomeSettings
::
instance
()
->
setIsRememberPwd
(
false
);
}
return
true
;
}
return
false
;
}
void
FMPLogin
::
onFocusChanged
(
QWidget
*
,
QWidget
*
now
)
...
...
@@ -84,3 +115,46 @@ void FMPLogin::onFocusChanged(QWidget *, QWidget *now)
// ui->numpad->setLineEdit(qobject_cast<QLineEdit*>(now));
}
}
void
FMPLogin
::
savePassword
(
const
QString
&
userName
,
const
QString
&
pwd
)
{
bool
isCreate
=
false
;
QString
fileName
=
qApp
->
applicationDirPath
()
+
"/.fmp"
;
QFile
file
(
fileName
);
isCreate
=
!
file
.
exists
();
if
(
!
file
.
open
(
QIODevice
::
WriteOnly
))
{
return
;
}
QDataStream
out
(
&
file
);
out
<<
encrypt
(
userName
.
toUtf8
());
out
<<
encrypt
(
pwd
.
toUtf8
());
file
.
close
();
if
(
isCreate
)
{
QString
program
=
"attrib"
;
QStringList
arguments
;
arguments
<<
"+h"
<<
fileName
;
QProcess
*
process
=
new
QProcess
(
this
);
process
->
start
(
program
,
arguments
);
process
->
waitForFinished
(
3000
);
}
}
void
FMPLogin
::
readPassword
(
QString
&
userName
,
QString
&
pwd
)
{
QFile
file
(
qApp
->
applicationDirPath
()
+
"/.fmp"
);
if
(
!
file
.
open
(
QIODevice
::
ReadOnly
))
{
return
;
}
QDataStream
out
(
&
file
);
QByteArray
n
,
p
;
out
>>
n
>>
p
;
userName
=
decrypt
(
n
);
pwd
=
decrypt
(
p
);
file
.
close
();
}
fmp_login.h
View file @
f0e1ed5f
...
...
@@ -26,6 +26,7 @@ public:
QString
userName
()
{
return
_userName
;}
QString
errorMsg
()
{
return
_errorMsg
;}
private
slots
:
void
on_login_btn_clicked
();
...
...
@@ -40,6 +41,9 @@ private:
QString
_url
;
QString
_storeId
;
QString
_partnerId
;
void
savePassword
(
const
QString
&
userName
,
const
QString
&
pwd
);
void
readPassword
(
QString
&
userName
,
QString
&
pwd
);
};
#endif // FMP_LOGIN_H
fmp_login.ui
View file @
f0e1ed5f
...
...
@@ -83,6 +83,12 @@
border-left: 0;
}
#remember_check {
font: 300 15px
"
Microsoft YaHei
"
;
max-height: 20px;
margin-bottom: 10px;
}
#login_btn {
min-height: 56px;
background: rgb(99, 148, 235);
...
...
@@ -200,7 +206,7 @@
<widget
class=
"QWidget"
name=
"user"
native=
"true"
>
<layout
class=
"QVBoxLayout"
name=
"verticalLayout_2"
>
<property
name=
"spacing"
>
<number>
25
</number>
<number>
0
</number>
</property>
<property
name=
"leftMargin"
>
<number>
124
</number>
...
...
@@ -219,6 +225,9 @@
<property
name=
"spacing"
>
<number>
0
</number>
</property>
<property
name=
"bottomMargin"
>
<number>
20
</number>
</property>
<item>
<widget
class=
"QLabel"
name=
"user_label"
>
<property
name=
"margin"
>
...
...
@@ -284,6 +293,16 @@
</layout>
</item>
<item>
<widget
class=
"QCheckBox"
name=
"remember_check"
>
<property
name=
"cursor"
>
<cursorShape>
PointingHandCursor
</cursorShape>
</property>
<property
name=
"text"
>
<string>
记住密码
</string>
</property>
</widget>
</item>
<item>
<widget
class=
"QPushButton"
name=
"login_btn"
>
<property
name=
"sizePolicy"
>
<sizepolicy
hsizetype=
"Preferred"
vsizetype=
"Preferred"
>
...
...
fmp_message.cpp
0 → 100644
View file @
f0e1ed5f
#
include
"fmp_message.h"
#include "ui_fmp_message.h"
FMPMessage
::
FMPMessage
(
QWidget
*
parent
)
:
QDialog
(
parent
),
ui
(
new
Ui
::
FMPMessage
)
{
ui
->
setupUi
(
this
);
setAttribute
(
Qt
::
WA_TranslucentBackground
);
ui
->
widget
->
setWindowOpacity
(
1
);
setGeometry
(
parent
->
geometry
());
this
->
move
(
parent
->
pos
());
setWindowFlags
(
Qt
::
FramelessWindowHint
|
Qt
::
Tool
);
connect
(
ui
->
btn_confirm
,
&
QPushButton
::
clicked
,
this
,
&
FMPMessage
::
accept
);
qRegisterMetaType
<
FMPMessage
::
Type
>
(
"FMPMessage::Type"
);
//setStyleSheet("QWidget#mainWdg{background:rgba(110,110,110,0.5)}");
}
FMPMessage
::~
FMPMessage
()
{
delete
ui
;
}
void
FMPMessage
::
SetContent
(
FMPMessage
::
Type
type
,
const
QString
&
msg
)
{
switch
(
type
)
{
case
FMPMessage
:
:
SUCCESS
:
ui
->
btn_confirm
->
setVisible
(
true
);
ui
->
label_logo
->
setStyleSheet
(
"#label_logo {background: url(:/img/loading.png) center no-repeat;}"
);
break
;
case
FMPMessage
:
:
ERROR
:
ui
->
btn_confirm
->
setVisible
(
true
);
ui
->
label_logo
->
setStyleSheet
(
"#label_logo {background: url(:/img/fmclient-icon_payment_fail.png) center no-repeat;}"
);
break
;
case
FMPMessage
:
:
LOADING
:
ui
->
label_logo
->
setStyleSheet
(
"#label_logo {background: url(:/img/loading.png) center no-repeat;}"
);
ui
->
btn_confirm
->
setVisible
(
false
);
break
;
default
:
ui
->
btn_confirm
->
setVisible
(
true
);
ui
->
label_logo
->
setStyleSheet
(
"#label_logo {background: url(:/img/loading.png) center no-repeat;}"
);
break
;
}
ui
->
label_msg
->
setText
(
msg
);
}
int
FMPMessage
::
critical
(
QWidget
*
parent
,
const
QString
&
msg
)
{
FMPMessage
window
(
parent
);
window
.
SetContent
(
FMPMessage
::
ERROR
,
msg
);
return
window
.
exec
();
}
fmp_message.h
0 → 100644
View file @
f0e1ed5f
#
ifndef
WAITDIALOG_H
#define WAITDIALOG_H
#include <QDialog>
namespace
Ui
{
class
FMPMessage
;
}
class
FMPMessage
:
public
QDialog
{
Q_OBJECT
public
:
explicit
FMPMessage
(
QWidget
*
parent
=
0
);
~
FMPMessage
();
typedef
enum
{
SUCCESS
=
0
,
ERROR
,
LOADING
}
Type
;
void
SetContent
(
FMPMessage
::
Type
type
,
const
QString
&
msg
);
static
int
critical
(
QWidget
*
parent
,
const
QString
&
msg
);
private
:
Ui
::
FMPMessage
*
ui
;
};
#endif // WAITDIALOG_H
fmp_message.ui
0 → 100644
View file @
f0e1ed5f
<?xml version="1.0" encoding="UTF-8"?>
<ui
version=
"4.0"
>
<class>
FMPMessage
</class>
<widget
class=
"QDialog"
name=
"FMPMessage"
>
<property
name=
"geometry"
>
<rect>
<x>
0
</x>
<y>
0
</y>
<width>
553
</width>
<height>
414
</height>
</rect>
</property>
<property
name=
"windowTitle"
>
<string>
Dialog
</string>
</property>
<property
name=
"styleSheet"
>
<string
notr=
"true"
>
#FMPPayWait
{
opacity: 223;
background-color: rgb(148, 148, 148, 0);
}
#label_logo {
background: url(:/img/loading.png) no-repeat center;
}
</string>
</property>
<layout
class=
"QHBoxLayout"
name=
"horizontalLayout_4"
>
<property
name=
"spacing"
>
<number>
0
</number>
</property>
<property
name=
"leftMargin"
>
<number>
0
</number>
</property>
<property
name=
"topMargin"
>
<number>
0
</number>
</property>
<property
name=
"rightMargin"
>
<number>
0
</number>
</property>
<property
name=
"bottomMargin"
>
<number>
0
</number>
</property>
<item>
<widget
class=
"QWidget"
name=
"mainWdg"
native=
"true"
>
<layout
class=
"QVBoxLayout"
name=
"verticalLayout_2"
>
<property
name=
"spacing"
>
<number>
0
</number>
</property>
<property
name=
"leftMargin"
>
<number>
0
</number>
</property>
<property
name=
"topMargin"
>
<number>
0
</number>
</property>
<property
name=
"rightMargin"
>
<number>
0
</number>
</property>
<property
name=
"bottomMargin"
>
<number>
0
</number>
</property>
<item>
<spacer
name=
"verticalSpacer_3"
>
<property
name=
"orientation"
>
<enum>
Qt::Vertical
</enum>
</property>
<property
name=
"sizeHint"
stdset=
"0"
>
<size>
<width>
20
</width>
<height>
182
</height>
</size>
</property>
</spacer>
</item>
<item>
<layout
class=
"QHBoxLayout"
name=
"horizontalLayout_3"
>
<item>
<spacer
name=
"horizontalSpacer_5"
>
<property
name=
"orientation"
>
<enum>
Qt::Horizontal
</enum>
</property>
<property
name=
"sizeHint"
stdset=
"0"
>
<size>
<width>
13
</width>
<height>
20
</height>
</size>
</property>
</spacer>
</item>
<item>
<widget
class=
"QWidget"
name=
"widget"
native=
"true"
>
<property
name=
"minimumSize"
>
<size>
<width>
344
</width>
<height>
222
</height>
</size>
</property>
<property
name=
"maximumSize"
>
<size>
<width>
344
</width>
<height>
222
</height>
</size>
</property>
<property
name=
"styleSheet"
>
<string
notr=
"true"
>
#widget
{
background-color: rgb(255, 255, 255);
border: 1 solid silver;
border-radius:8px;
opacity:0;
}
</string>
</property>
<layout
class=
"QVBoxLayout"
name=
"verticalLayout"
>
<property
name=
"spacing"
>
<number>
0
</number>
</property>
<property
name=
"leftMargin"
>
<number>
0
</number>
</property>
<property
name=
"topMargin"
>
<number>
0
</number>
</property>
<property
name=
"rightMargin"
>
<number>
0
</number>
</property>
<property
name=
"bottomMargin"
>
<number>
0
</number>
</property>
<item>
<spacer
name=
"verticalSpacer"
>
<property
name=
"orientation"
>
<enum>
Qt::Vertical
</enum>
</property>
<property
name=
"sizeHint"
stdset=
"0"
>
<size>
<width>
20
</width>
<height>
40
</height>
</size>
</property>
</spacer>
</item>
<item>
<layout
class=
"QHBoxLayout"
name=
"horizontalLayout_2"
>
<property
name=
"spacing"
>
<number>
0
</number>
</property>
<item>
<spacer
name=
"horizontalSpacer"
>
<property
name=
"orientation"
>
<enum>
Qt::Horizontal
</enum>
</property>
<property
name=
"sizeHint"
stdset=
"0"
>
<size>
<width>
40
</width>
<height>
20
</height>
</size>
</property>
</spacer>
</item>
<item>
<widget
class=
"QLabel"
name=
"label_logo"
>
<property
name=
"minimumSize"
>
<size>
<width>
64
</width>
<height>
64
</height>
</size>
</property>
<property
name=
"maximumSize"
>
<size>
<width>
64
</width>
<height>
64
</height>
</size>
</property>
<property
name=
"styleSheet"
>
<string
notr=
"true"
/>
</property>
<property
name=
"text"
>
<string/>
</property>
</widget>
</item>
<item>
<widget
class=
"QLabel"
name=
"label_msg"
>
<property
name=
"minimumSize"
>
<size>
<width>
161
</width>
<height>
0
</height>
</size>
</property>
<property
name=
"maximumSize"
>
<size>
<width>
16777215
</width>
<height>
16777215
</height>
</size>
</property>
<property
name=
"font"
>
<font>
<family>
微软雅黑
</family>
<pointsize>
-1
</pointsize>
<weight>
50
</weight>
<italic>
false
</italic>
<bold>
false
</bold>
</font>
</property>
<property
name=
"styleSheet"
>
<string
notr=
"true"
>
#label_msg
{
color: rgb(100, 100, 100);
font: 22px
"
微软雅黑
"
;
}
</string>
</property>
<property
name=
"text"
>
<string>
支付中...
</string>
</property>
<property
name=
"wordWrap"
>
<bool>
true
</bool>
</property>
</widget>
</item>
<item>
<spacer
name=
"horizontalSpacer_2"
>
<property
name=
"orientation"
>
<enum>
Qt::Horizontal
</enum>
</property>
<property
name=
"sizeType"
>
<enum>
QSizePolicy::Expanding
</enum>
</property>
<property
name=
"sizeHint"
stdset=
"0"
>
<size>
<width>
13
</width>
<height>
57
</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item>
<spacer
name=
"verticalSpacer_2"
>
<property
name=
"orientation"
>
<enum>
Qt::Vertical
</enum>
</property>
<property
name=
"sizeHint"
stdset=
"0"
>
<size>
<width>
20
</width>
<height>
40
</height>
</size>
</property>
</spacer>
</item>
<item>
<widget
class=
"QPushButton"
name=
"btn_confirm"
>
<property
name=
"minimumSize"
>
<size>
<width>
121
</width>
<height>
62
</height>
</size>
</property>
<property
name=
"maximumSize"
>
<size>
<width>
16777215
</width>
<height>
62
</height>
</size>
</property>
<property
name=
"cursor"
>
<cursorShape>
PointingHandCursor
</cursorShape>
</property>
<property
name=
"styleSheet"
>
<string
notr=
"true"
>
#btn_confirm
{
font: normal 26px
"
微软雅黑
"
;
border: 1 solid silver;
border-top: 0;
border-bottom-right-radius: 8px;
border-bottom-left-radius: 8px;
background-color: rgb(93, 144, 236);
color: rgb(255, 255, 255);
}
</string>
</property>
<property
name=
"text"
>
<string>
确认
</string>
</property>
</widget>
</item>
</layout>
<zorder>
verticalSpacer
</zorder>
<zorder>
verticalSpacer_2
</zorder>
<zorder>
btn_confirm
</zorder>
</widget>
</item>
<item>
<spacer
name=
"horizontalSpacer_6"
>
<property
name=
"orientation"
>
<enum>
Qt::Horizontal
</enum>
</property>
<property
name=
"sizeHint"
stdset=
"0"
>
<size>
<width>
13
</width>
<height>
20
</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item>
<spacer
name=
"verticalSpacer_4"
>
<property
name=
"orientation"
>
<enum>
Qt::Vertical
</enum>
</property>
<property
name=
"sizeHint"
stdset=
"0"
>
<size>
<width>
20
</width>
<height>
181
</height>
</size>
</property>
</spacer>
</item>
</layout>
<zorder>
verticalSpacer_4
</zorder>
<zorder>
verticalSpacer_3
</zorder>
<zorder></zorder>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment