tazawy's picture
<!DOCTYPE html>
2bda0cc verified
Raw History Blame Contribute Delete
2.7 kB
document.addEventListener('DOMContentLoaded', function() {
const pinInput = document.getElementById('pin');
const unlockBtn = document.getElementById('unlockBtn');
const fingerprintBtn = document.getElementById('fingerprintBtn');
// Mock authentication functions
async function checkPin() {
const enteredPin = pinInput.value;
if (!enteredPin || enteredPin.length < 4) {
showToast('الرجاء إدخال رمز PIN مكون من 4 أرقام على الأقل', 'error');
return;
}
// In a real app, you would check against stored hash
showToast('جارٍ التحقق...', 'info');
// Simulate API call
setTimeout(() => {
// Default PIN for demo: 1234
if (enteredPin === '1234') {
showToast('تم فتح القفل بنجاح!', 'success');
// Redirect to home page
setTimeout(() => {
window.location.href = 'home.html';
}, 1000);
} else {
showToast('رمز PIN غير صحيح', 'error');
}
}, 1500);
}
async function authenticateWithFingerprint() {
showToast('جارٍ التحقق بالبصمة...', 'info');
// Check if browser supports WebAuthn
if (!window.PublicKeyCredential) {
showToast('المتصفح لا يدعم المصادقة البيومترية', 'error');
return;
}
// Simulate fingerprint auth
setTimeout(() => {
const isSuccess = Math.random() > 0.2; // 80% success rate for demo
if (isSuccess) {
showToast('تم المصادقة بنجاح!', 'success');
setTimeout(() => {
window.location.href = 'home.html';
}, 1000);
} else {
showToast('فشل المصادقة، حاول مرة أخرى', 'error');
}
}, 2000);
}
// Event listeners
unlockBtn.addEventListener('click', checkPin);
fingerprintBtn.addEventListener('click', authenticateWithFingerprint);
// Allow submitting with Enter key
pinInput.addEventListener('keypress', function(e) {
if (e.key === 'Enter') {
checkPin();
}
});
});
function showToast(message, type) {
const toast = document.createElement('custom-toast');
toast.setAttribute('message', message);
toast.setAttribute('type', type);
document.body.appendChild(toast);
setTimeout(() => {
toast.remove();
}, 3000);
}