Moved hash function into seperate file.
NOTE: useful for changePassword, which requires the hash password functionality as well.
This commit is contained in:
parent
e3ca4fafa6
commit
569dda01fd
2 changed files with 118 additions and 121 deletions
8
lib/backend/crypto.dart
Normal file
8
lib/backend/crypto.dart
Normal file
|
@ -0,0 +1,8 @@
|
|||
import 'dart:convert';
|
||||
import 'package:crypto/crypto.dart';
|
||||
|
||||
String hashPassword(String pw) {
|
||||
var bytes = utf8.encode(pw);
|
||||
final password = sha256.convert(bytes).toString();
|
||||
return password;
|
||||
}
|
|
@ -1,4 +1,5 @@
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:outbag_app/backend/crypto.dart';
|
||||
import 'package:outbag_app/backend/request.dart';
|
||||
import 'package:outbag_app/backend/user.dart';
|
||||
import 'package:outbag_app/tools/fetch_wrapper.dart';
|
||||
|
@ -128,8 +129,7 @@ class _AuthPageState extends State<AuthPage> {
|
|||
padding: const EdgeInsets.all(8),
|
||||
child: TextField(
|
||||
controller: _ctrPasswordRpt,
|
||||
keyboardType:
|
||||
TextInputType.visiblePassword,
|
||||
keyboardType: TextInputType.visiblePassword,
|
||||
obscureText: true,
|
||||
decoration: const InputDecoration(
|
||||
prefixIcon: Icon(Icons.lock),
|
||||
|
@ -150,13 +150,11 @@ class _AuthPageState extends State<AuthPage> {
|
|||
padding: const EdgeInsets.all(8),
|
||||
child: TextField(
|
||||
controller: _ctrOTA,
|
||||
keyboardType:
|
||||
TextInputType.visiblePassword,
|
||||
keyboardType: TextInputType.visiblePassword,
|
||||
decoration: const InputDecoration(
|
||||
prefixIcon: Icon(Icons.key),
|
||||
labelText: 'OTA',
|
||||
hintText:
|
||||
'One-Time-Authorization token',
|
||||
hintText: 'One-Time-Authorization token',
|
||||
helperText:
|
||||
'This token might be required if the server is rate limited',
|
||||
border: OutlineInputBorder(),
|
||||
|
@ -166,9 +164,7 @@ class _AuthPageState extends State<AuthPage> {
|
|||
]
|
||||
: []),
|
||||
],
|
||||
)
|
||||
)
|
||||
),
|
||||
))),
|
||||
floatingActionButton: FloatingActionButton.extended(
|
||||
onPressed: () async {
|
||||
setState(() {
|
||||
|
@ -227,13 +223,9 @@ class _AuthPageState extends State<AuthPage> {
|
|||
}
|
||||
|
||||
// hash password
|
||||
var bytes = utf8.encode(_ctrPassword.text);
|
||||
final password = sha256.convert(bytes).toString();
|
||||
final password = hashPassword(_ctrPassword.text);
|
||||
|
||||
doNetworkRequest(
|
||||
scaffMgr,
|
||||
needUser: false,
|
||||
req: (_) {
|
||||
doNetworkRequest(scaffMgr, needUser: false, req: (_) {
|
||||
if (widget.mode == Mode.signin) {
|
||||
return postUnauthorized(
|
||||
target: server,
|
||||
|
@ -264,21 +256,18 @@ class _AuthPageState extends State<AuthPage> {
|
|||
'OTA': _ctrOTA.text
|
||||
});
|
||||
}
|
||||
},
|
||||
onOK: (body) async {
|
||||
}, onOK: (body) async {
|
||||
// authorize user
|
||||
await User(
|
||||
username: _ctrUsername.text,
|
||||
password: password,
|
||||
server: server)
|
||||
.toDisk();
|
||||
},
|
||||
after: () {
|
||||
}, after: () {
|
||||
setState(() {
|
||||
showSpinner = false;
|
||||
});
|
||||
}
|
||||
);
|
||||
});
|
||||
},
|
||||
label: Text(modeName),
|
||||
icon: const Icon(Icons.check),
|
||||
|
|
Loading…
Reference in a new issue