commit
c3495b2f8c
@ -1,30 +1,51 @@
|
||||
import 'dart:io' show Platform;
|
||||
import 'dart:io' as io;
|
||||
import 'dart:async';
|
||||
import 'package:path_provider/path_provider.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:path/path.dart' as p;
|
||||
|
||||
class Config extends ChangeNotifier {
|
||||
String appDirPath = "";
|
||||
late io.Directory appDirPath;
|
||||
late List<int> charac;
|
||||
|
||||
Config();
|
||||
Config() {
|
||||
appDirPath = io.Directory("");
|
||||
charac = [];
|
||||
}
|
||||
|
||||
void setAppDirPath() async {
|
||||
Future<void> setAppDirPath() async {
|
||||
if (Platform.isLinux) {
|
||||
appDirPath = "${Platform.environment['HOME'].toString()}/.passworld/";
|
||||
setDirectory();
|
||||
appDirPath = io.Directory(
|
||||
"${Platform.environment['HOME'].toString()}/.passworld/");
|
||||
await setDirectory();
|
||||
} else {
|
||||
// appDirPath = io.Directory("/data/user/0");
|
||||
appDirPath = await getApplicationDocumentsDirectory();
|
||||
await setDirectory();
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> setDirectory() async {
|
||||
if (!io.Directory(appDirPath.path).existsSync()) {
|
||||
io.Directory(appDirPath.path).createSync();
|
||||
}
|
||||
if (!io.File(p.join(appDirPath.path, "file.txt")).existsSync()) {
|
||||
print("LE FICHIER NEXISTE PAS ");
|
||||
io.File("${appDirPath.path}/file.txt").create();
|
||||
} else {
|
||||
var dir = await getApplicationDocumentsDirectory();
|
||||
appDirPath = dir.path;
|
||||
print("LE FICHIER EXISTE");
|
||||
}
|
||||
}
|
||||
|
||||
void setDirectory() {
|
||||
if (!io.Directory(appDirPath).existsSync()) {
|
||||
io.Directory(appDirPath).createSync();
|
||||
void addCharacter(int i) {
|
||||
if (charac.contains(i)) {
|
||||
charac.remove(i);
|
||||
} else {
|
||||
charac.add(i);
|
||||
}
|
||||
if(!io.File("${appDirPath}file.txt").existsSync()) {
|
||||
io.File("${appDirPath}file.txt").createSync();
|
||||
}
|
||||
|
||||
void clearCharacter() {
|
||||
charac.clear();
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,46 @@
|
||||
/*import 'dart:io';
|
||||
import 'package:aes_crypt/aes_crypt.dart';
|
||||
import 'package:flutter/widgets.dart';
|
||||
import 'package:test/Classes/Exception/storageException.dart';
|
||||
import 'dart:typed_data';
|
||||
import 'storage.dart';
|
||||
|
||||
class EncryptFile implements Exception{
|
||||
static void encrypt_file(String path,String id) async{
|
||||
AesCrypt crypt = AesCrypt();
|
||||
crypt.setOverwriteMode(AesCryptOwMode.warn);
|
||||
crypt.setPassword('my cool password'); // à changer
|
||||
String encFilepath;
|
||||
try {
|
||||
encFilepath = crypt.encryptTextToFileSync((await Storage.getKey("${id}Key")).base64+(await Storage.getIV("${id}IV")).base64, path);
|
||||
} on AesCryptException catch (e) {
|
||||
if (e.type == AesCryptExceptionType.destFileExists) {
|
||||
throw AesCryptException("Fichier déjà existant !!", e.type);
|
||||
}
|
||||
else{
|
||||
throw AesCryptArgumentError("Erreur lors du chiffrage du fichier.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static String decrypt_file(String path) {
|
||||
AesCrypt crypt = AesCrypt();
|
||||
crypt.setOverwriteMode(AesCryptOwMode.warn);
|
||||
crypt.setPassword('my cool password'); // voir pour mettre le mdp de l'utilisateur
|
||||
String key;
|
||||
try{
|
||||
key = crypt.decryptTextFromFileSync(path);
|
||||
if(key.isEmpty){
|
||||
throw AesCryptArgumentError("Erreur lors du déchiffrage du fichier");
|
||||
}
|
||||
return key;
|
||||
} on AesCryptException catch (e){
|
||||
if (e.type == AesCryptExceptionType.destFileExists) {
|
||||
throw AesCryptException("Erreur lors du déchiffrage du fichier", e.type);
|
||||
}
|
||||
else{
|
||||
throw AesCryptArgumentError("Erreur lors du déchiffrage du fichier");
|
||||
}
|
||||
}
|
||||
}
|
||||
}*/
|
@ -0,0 +1,22 @@
|
||||
class Strength{
|
||||
static checkStrength(String value)
|
||||
{
|
||||
RegExp numReg = RegExp(r".*[0-9].*");
|
||||
RegExp letterReg = RegExp(r".*[A-Za-z].*");
|
||||
var pwd = value.trim();
|
||||
|
||||
if (pwd.isEmpty) {
|
||||
return 0;
|
||||
} else if (pwd.length < 6) {
|
||||
return (1 / 4);
|
||||
} else if (pwd.length < 8) {
|
||||
return (2 / 4);
|
||||
} else {
|
||||
if (!letterReg.hasMatch(pwd) || !numReg.hasMatch(pwd)) {
|
||||
return (3 / 4);
|
||||
} else {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,35 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:pretty_qr_code/pretty_qr_code.dart';
|
||||
import '../../Classes/storage.dart';
|
||||
import 'package:screen_brightness_util/screen_brightness_util.dart';
|
||||
|
||||
showQrcode(BuildContext context, String id) async {
|
||||
AlertDialog alert = AlertDialog(
|
||||
backgroundColor: Colors.deepPurple[300],
|
||||
content: PrettyQr(
|
||||
image: const AssetImage('assets/bereal.png'), //mettre l'icone de l'app
|
||||
typeNumber: 6,
|
||||
size: 500,
|
||||
data:
|
||||
(await Storage.getKey(id)).base64 + (await Storage.getIV(id)).base64,
|
||||
errorCorrectLevel: QrErrorCorrectLevel.M,
|
||||
roundEdges: false,
|
||||
),
|
||||
);
|
||||
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (BuildContext context) {
|
||||
return alert;
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> setBrightness(double brightness) async {
|
||||
try {
|
||||
await ScreenBrightnessUtil().setBrightness(brightness);
|
||||
} catch (e) {
|
||||
print(e);
|
||||
throw 'Failed to set brightness';
|
||||
}
|
||||
}
|
@ -0,0 +1,44 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:ai_barcode_scanner/ai_barcode_scanner.dart';
|
||||
import '../../Classes/storage.dart';
|
||||
import 'package:encrypt/encrypt.dart' as encrypt;
|
||||
|
||||
class Scanner extends StatefulWidget {
|
||||
const Scanner({Key? key}) : super(key: key);
|
||||
|
||||
@override
|
||||
State<Scanner> createState() => _Scanner();
|
||||
}
|
||||
|
||||
class _Scanner extends State<Scanner> {
|
||||
String barcode = "";
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return AiBarcodeScanner(
|
||||
// validateText: 'https://', // link to be validated
|
||||
// validateType: ValidateType.startsWith,
|
||||
onScan: (String value) {
|
||||
debugPrint(value);
|
||||
setState(() {
|
||||
barcode = value;
|
||||
Storage.storing(encrypt.Key.fromBase64(barcode.substring(0, 43)),
|
||||
encrypt.IV.fromBase64(barcode.substring(44)), "id");
|
||||
});
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// Add this to use the qrcode
|
||||
///
|
||||
/// if (Platform.isLinux || Platform.isWindows) {
|
||||
/// showAlertDialog(context,
|
||||
/// "Cette fonctionnalité n'est pas disponible sur votre appareil !!");
|
||||
/// } else {
|
||||
/// Navigator.push(
|
||||
/// context,
|
||||
/// MaterialPageRoute<dynamic>(
|
||||
/// builder: (context) => const Scanner()
|
||||
/// )
|
||||
/// )
|
||||
/// }
|
@ -0,0 +1,51 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import '../../Classes/config.dart';
|
||||
|
||||
// Widget for all inputs of addPasswordPage
|
||||
class CharactereInputWidget extends StatefulWidget {
|
||||
// Variables
|
||||
final String character;
|
||||
final int no;
|
||||
|
||||
const CharactereInputWidget(
|
||||
{super.key, required this.character, required this.no});
|
||||
|
||||
@override
|
||||
State<CharactereInputWidget> createState() => _CharactereInputWidgetState();
|
||||
}
|
||||
|
||||
class _CharactereInputWidgetState extends State<CharactereInputWidget> {
|
||||
bool pressAttention = true;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
// Media Query
|
||||
var size = MediaQuery.of(context).size;
|
||||
double w = size.width; //* MediaQuery.of(context).devicePixelRatio;
|
||||
double h = size.height;
|
||||
|
||||
// Widget
|
||||
return SizedBox(
|
||||
height: h * 0.1,
|
||||
width: w * 0.1,
|
||||
child: ElevatedButton(
|
||||
onPressed: () => {
|
||||
setState(() {
|
||||
pressAttention = !pressAttention;
|
||||
context.read<Config>().addCharacter(widget.no);
|
||||
})
|
||||
},
|
||||
style: ButtonStyle(
|
||||
backgroundColor: MaterialStateProperty.all(
|
||||
pressAttention ? Colors.white : Colors.deepPurple[300]),
|
||||
),
|
||||
child: Text(
|
||||
widget.character,
|
||||
style: TextStyle(
|
||||
color: pressAttention ? Colors.black : Colors.white,
|
||||
fontSize: w * 0.045,
|
||||
fontWeight: FontWeight.bold),
|
||||
)));
|
||||
}
|
||||
}
|
@ -0,0 +1,34 @@
|
||||
import 'package:bcrypt/bcrypt.dart';
|
||||
import 'package:encrypt/encrypt.dart';
|
||||
|
||||
void display(bool res) {
|
||||
print("Check password: $res");
|
||||
return;
|
||||
}
|
||||
|
||||
void trueFunc(password, hash) {
|
||||
bool res = BCrypt.checkpw(password, hash);
|
||||
display(res);
|
||||
return;
|
||||
}
|
||||
|
||||
void aurianFunc(String password, String salt, String hash) {
|
||||
var newHash = BCrypt.hashpw(password, salt);
|
||||
display(newHash == hash);
|
||||
return;
|
||||
}
|
||||
|
||||
void main() async {
|
||||
var password = "coucou123";
|
||||
var salt = BCrypt.gensalt();
|
||||
var hash = BCrypt.hashpw(password, salt);
|
||||
aurianFunc(password, salt, hash);
|
||||
trueFunc(password, hash);
|
||||
|
||||
var iv = IV.fromSecureRandom(16);
|
||||
var key = Key.fromSecureRandom(32);
|
||||
var encrypter = Encrypter(AES(key));
|
||||
|
||||
print(encrypter.encrypt(hash, iv: iv).base64);
|
||||
print(encrypter.encrypt(hash, iv: iv).base64);
|
||||
}
|
Loading…
Reference in new issue