Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
M
MiYaFastCashier
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
jiangjiantao
MiYaFastCashier
Commits
9e3d311b
Commit
9e3d311b
authored
Nov 02, 2022
by
赵鹏翔
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
授权码加密到文件,优化存储
parent
8aea2dfe
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
26 additions
and
4 deletions
+26
-4
AccountPasswordManageKit.kt
.../miya/fastcashier/util/manage/AccountPasswordManageKit.kt
+15
-4
BaseFunction.kt
...main/java/com/fastcashier/lib_common/util/BaseFunction.kt
+11
-0
No files found.
app/src/main/java/com/miya/fastcashier/util/manage/AccountPasswordManageKit.kt
View file @
9e3d311b
...
...
@@ -4,18 +4,21 @@ import android.Manifest
import
android.os.Environment
import
android.text.TextUtils
import
androidx.appcompat.app.AppCompatActivity
import
com.blankj.utilcode.util.EncodeUtils
import
com.blankj.utilcode.util.FileIOUtils
import
com.blankj.utilcode.util.FileUtils
import
com.blankj.utilcode.util.ToastUtils
import
com.fastcashier.lib_common.function.account.AccountService.getAccountPassword
import
com.fastcashier.lib_common.function.account.AccountService.getUserName
import
com.fastcashier.lib_common.function.account.AccountService.setAccountPassword
import
com.fastcashier.lib_common.util.isBase64
import
com.permissionx.guolindev.PermissionX
import
java.nio.charset.Charset
import
java.util.concurrent.Executors
/**
* 类描述:账户管理员密码管理
* 概述:
* 概述:
密码以base64处理存到本地,初始化时解码到内存
* 创建人:zpxiang
* 创建时间:2022/4/1
* 修改人:
...
...
@@ -34,6 +37,7 @@ class AccountPasswordManageKit private constructor() {
}
return
sInstance
}
@Synchronized
fun
get
():
AccountPasswordManageKit
{
return
instance
!!
...
...
@@ -67,9 +71,14 @@ class AccountPasswordManageKit private constructor() {
fun
initAccountPassword
(
context
:
AppCompatActivity
,
callback
:
AccountPasswordManageCallback
?)
{
if
(
FileUtils
.
isFileExists
(
currentAccountFilePath
))
{
Executors
.
newCachedThreadPool
().
execute
{
val
password
=
FileIOUtils
.
readFile2String
(
val
password
64
=
FileIOUtils
.
readFile2String
(
currentAccountFilePath
)
val
password
=
if
(
isBase64
(
password64
))
EncodeUtils
.
base64Decode
(
password64
).
toString
(
Charset
.
defaultCharset
())
else
password64
setAccountPassword
(
password
)
context
.
runOnUiThread
{
callback
?.
onPasswordGet
(
password
)
}
}
...
...
@@ -77,11 +86,12 @@ class AccountPasswordManageKit private constructor() {
}
setAccountPassword
(
ACCOUNT_DEFAULT_PASSWORD
)
callback
?.
onPasswordGet
(
ACCOUNT_DEFAULT_PASSWORD
)
val
password64
=
EncodeUtils
.
base64Encode2String
(
ACCOUNT_DEFAULT_PASSWORD
.
toByteArray
())
if
(
FileUtils
.
createOrExistsFile
(
currentAccountFilePath
))
{
Executors
.
newCachedThreadPool
().
execute
{
FileIOUtils
.
writeFileFromString
(
currentAccountFilePath
,
ACCOUNT_DEFAULT_PASSWORD
password64
)
}
}
...
...
@@ -117,8 +127,9 @@ class AccountPasswordManageKit private constructor() {
FileUtils
.
deleteAllInDir
(
currentAccountFilePath
)
}
if
(
FileUtils
.
createOrExistsFile
(
currentAccountFilePath
))
{
val
password64
=
EncodeUtils
.
base64Encode2String
(
password
.
toByteArray
())
Executors
.
newCachedThreadPool
()
.
execute
{
FileIOUtils
.
writeFileFromString
(
currentAccountFilePath
,
password
)
}
.
execute
{
FileIOUtils
.
writeFileFromString
(
currentAccountFilePath
,
password
64
)
}
}
}
}
\ No newline at end of file
lib_common/src/main/java/com/fastcashier/lib_common/util/BaseFunction.kt
View file @
9e3d311b
...
...
@@ -11,6 +11,7 @@ import android.text.TextUtils
import
java.net.Inet4Address
import
java.net.NetworkInterface
import
java.net.SocketException
import
java.util.regex.Pattern
fun
isEmpty
(
s
:
String
?):
Boolean
{
return
TextUtils
.
isEmpty
(
s
)
...
...
@@ -144,3 +145,13 @@ fun isNetworkConnected(context: Context?): Boolean {
}
return
false
}
/**
* 判断是否为Base64编码后的数据
*/
fun
isBase64
(
str
:
String
):
Boolean
{
val
base64Pattern
=
"^([A-Za-z0-9+/]{4})*([A-Za-z0-9+/]{4}|[A-Za-z0-9+/]{3}=|[A-Za-z0-9+/]{2}==)$"
return
Pattern
.
matches
(
base64Pattern
,
str
)
}
\ No newline at end of file
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