zeba_academy_secure_auth 0.0.1
zeba_academy_secure_auth: ^0.0.1 copied to clipboard
A secure Flutter authentication package with local PIN/Pattern, biometrics, offline login, session management, and root/jailbreak detection.
example/lib/main.dart
import 'package:flutter/material.dart';
import 'package:pattern_lock/pattern_lock.dart';
import 'package:zeba_academy_secure_auth/zeba_academy_secure_auth.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
title: 'Secure Auth Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
inputDecorationTheme: const InputDecorationTheme(
border: OutlineInputBorder(),
),
),
home: const LoginScreen(),
);
}
}
class LoginScreen extends StatefulWidget {
const LoginScreen({super.key});
@override
State<LoginScreen> createState() => _LoginScreenState();
}
class _LoginScreenState extends State<LoginScreen> {
final _auth = SecureAuthService();
final _pinController = TextEditingController();
void _showSnack(String message, {bool success = true}) {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text(message),
backgroundColor: success ? Colors.green : Colors.red,
duration: const Duration(seconds: 2),
),
);
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('Secure Auth Demo'),
centerTitle: true,
elevation: 2,
),
body: SingleChildScrollView(
padding: const EdgeInsets.all(16),
child: Column(
children: [
// PIN Login Card
Card(
elevation: 4,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(12)),
child: Padding(
padding: const EdgeInsets.all(16),
child: Column(
children: [
const Text(
'Login with PIN',
style:
TextStyle(fontSize: 18, fontWeight: FontWeight.bold),
),
const SizedBox(height: 12),
TextField(
controller: _pinController,
keyboardType: TextInputType.number,
obscureText: true,
decoration: const InputDecoration(
labelText: 'Enter PIN',
prefixIcon: Icon(Icons.lock),
),
),
const SizedBox(height: 12),
ElevatedButton.icon(
onPressed: () async {
final success = await _auth.verifyPin(_pinController.text);
if (success) {
await _auth.startSession();
_showSnack('PIN verified!');
} else {
_showSnack('Incorrect PIN', success: false);
}
},
icon: const Icon(Icons.login),
label: const Text('Login'),
style: ElevatedButton.styleFrom(
minimumSize: const Size.fromHeight(40)),
),
],
),
),
),
const SizedBox(height: 24),
// Pattern Login Card
Card(
elevation: 4,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(12)),
child: Padding(
padding: const EdgeInsets.all(16),
child: Column(
children: [
const Text(
'Login with Pattern',
style:
TextStyle(fontSize: 18, fontWeight: FontWeight.bold),
),
const SizedBox(height: 12),
SizedBox(
height: 200,
child: PatternLock(
selectedColor: Colors.blue,
notSelectedColor: Colors.grey[300]!,
dimension: 3,
showInput: true,
onInputComplete: (pattern) async {
final patternString = pattern.join();
final success = await _auth.verifyPattern(patternString);
if (success) {
await _auth.startSession();
_showSnack('Pattern verified!');
} else {
_showSnack('Incorrect Pattern', success: false);
}
},
),
),
],
),
),
),
const SizedBox(height: 24),
// Biometric Login Card
Card(
elevation: 4,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(12)),
child: Padding(
padding: const EdgeInsets.all(16),
child: Column(
children: [
const Text(
'Login with Biometrics',
style:
TextStyle(fontSize: 18, fontWeight: FontWeight.bold),
),
const SizedBox(height: 12),
ElevatedButton.icon(
onPressed: () async {
final success = await _auth.authenticateBiometric();
if (success) {
await _auth.startSession();
_showSnack('Biometric verified!');
} else {
_showSnack('Biometric failed', success: false);
}
},
icon: const Icon(Icons.fingerprint),
label: const Text('Login'),
style: ElevatedButton.styleFrom(
minimumSize: const Size.fromHeight(40)),
),
],
),
),
),
],
),
),
);
}
}