Sindbad~EG File Manager
# Password Reset System - Installation & Testing Guide
## โ
Files Created
1. **forgot-password.php** - Request password reset
2. **reset-password.php** - Set new password with token
3. **EmailService::sendPasswordResetEmail()** - Instant email delivery
---
## ๐๏ธ Database Table
The system automatically creates the `password_resets` table on first use:
```sql
CREATE TABLE IF NOT EXISTS password_resets (
id INT PRIMARY KEY AUTO_INCREMENT,
user_id INT NOT NULL,
user_type ENUM('admin', 'member') NOT NULL,
email VARCHAR(255) NOT NULL,
token VARCHAR(255) NOT NULL,
expires_at DATETIME NOT NULL,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
used TINYINT(1) DEFAULT 0,
UNIQUE KEY unique_user (user_id, user_type),
INDEX idx_token (token),
INDEX idx_expires (expires_at)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4
```
**No manual installation needed!** Table is created automatically.
---
## ๐ Features
### **For Users:**
- โ
Separate flows for Admin & Member
- โ
Email validation
- โ
Token-based reset (64 characters)
- โ
1-hour expiration
- โ
One-time use tokens
- โ
Password strength indicator
- โ
Real-time password match validation
- โ
Security best practices
### **Email Features:**
- โก **Instant delivery** (not queued)
- ๐จ Professional HTML template
- ๐ Clickable reset button
- ๐ Plain text URL fallback
- โฐ Expiration warning
- ๐ก๏ธ Security notices
---
## ๐งช Testing Guide
### **Test Member Password Reset:**
1. **Request Reset:**
- Go to `http://localhost/copmadinaarea/forgot-password.php`
- Select "Member"
- Enter member email
- Click "Send Reset Link"
2. **Check Email:**
- Email arrives instantly
- Click "Reset Password" button
- Or copy/paste URL
3. **Reset Password:**
- Enter new password (min 6 characters)
- Confirm password
- See password strength indicator
- Click "Reset Password"
4. **Login:**
- Go to member login
- Use new password
- Success! โ
### **Test Admin Password Reset:**
1. **Request Reset:**
- Go to `http://localhost/copmadinaarea/forgot-password.php`
- Select "Admin"
- Enter admin email
- Click "Send Reset Link"
2. **Follow same steps** as member test
---
## ๐ง Email Template
**Subject:** Password Reset Request
**Content:**
```
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Password Reset Request โ
โ โ
โ Dear [Name], โ
โ We received a request to reset... โ
โ โ
โ [ Reset Password ] โ Button โ
โ โ
โ Link: https://... โ
โ Expires: 1 hour โ
โ โ
โ Security notice... โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
```
---
## ๐ Security Features
| Feature | Implementation |
|---------|----------------|
| **Token Length** | 64 characters (32 bytes hex) |
| **Expiration** | 1 hour |
| **One-time Use** | Token marked as used after reset |
| **Unique Constraint** | One active reset per user |
| **HTTPS Ready** | Works with SSL/TLS |
| **Email Privacy** | Doesn't reveal if email exists |
| **Password Hashing** | PHP password_hash() |
---
## ๐ฏ User Flow
### **Complete Password Reset Flow:**
```
User forgets password
โ
Goes to forgot-password.php
โ
Selects user type (Admin/Member)
โ
Enters email address
โ
Clicks "Send Reset Link"
โ
Email sent instantly โก
โ
User opens email
โ
Clicks reset button/link
โ
Redirected to reset-password.php?token=xxx&type=xxx
โ
Token validated (not expired, not used)
โ
Enter new password
โ
Password strength checked
โ
Confirm password match
โ
Click "Reset Password"
โ
Password updated in database
โ
Token marked as used
โ
Success! Redirect to login
โ
Login with new password โ
```
---
## ๐ Integration Points
### **Login Pages Already Updated:**
**login.php (Member):**
```html
<a href="forgot-password.php">Forgot password?</a>
```
**admin-login.php (Admin):**
```html
<a href="forgot-password.php">Forgot password?</a>
```
Both pages have working "Forgot password?" links!
---
## ๐พ Database Updates
**For Admin Users:**
```sql
UPDATE users SET password = '[hashed]' WHERE id = ?
```
**For Member Users:**
```sql
UPDATE member_accounts SET password_hash = '[hashed]' WHERE member_id = ?
```
---
## โ ๏ธ Requirements
โ
**Email Service Enabled** - SMTP must be configured
โ
**EmailService Class** - Already created
โ
**Symfony Mailer** - For sending emails
โ
**Database Access** - For token storage
---
## ๐จ UI Features
### **Forgot Password Page:**
- ๐ฏ User type selector (Member/Admin)
- ๐ง Email input field
- ๐จ Gradient design (blue-purple-yellow)
- ๐ฑ Fully responsive
- โ
Success/error messages
- ๐ Links to both login pages
### **Reset Password Page:**
- ๐ New password field
- ๐ Confirm password field
- ๐๏ธ Show/hide password toggle
- ๐ Password strength meter
- โ Real-time match validation
- โฐ Token expiration handling
- ๐ Success confirmation
---
## ๐ Troubleshooting
### **Email Not Arriving:**
1. Check SMTP settings in database
2. Check email_settings table `is_enabled = 1`
3. Check PHP error logs
4. Test with `fix_smtp_settings.php`
### **Invalid Token:**
1. Token expires after 1 hour
2. Token can only be used once
3. Check link was copied correctly
4. Request new reset if expired
### **Password Not Updating:**
1. Check password meets requirements (6+ chars)
2. Check passwords match
3. Verify database connection
4. Check user exists in database
---
## ๐ Production Tips
1. **Use HTTPS** - Protect reset tokens in transit
2. **Rate Limiting** - Prevent abuse (max 3 requests/hour)
3. **Email Logging** - Track reset attempts
4. **Monitor Tokens** - Clean up expired tokens (cron job)
5. **User Notifications** - Alert on successful reset
---
## ๐ Maintenance
### **Clean Up Old Tokens (Optional Cron Job):**
```sql
DELETE FROM password_resets
WHERE expires_at < NOW()
OR (used = 1 AND created_at < DATE_SUB(NOW(), INTERVAL 7 DAY))
```
Run weekly to keep table clean.
---
## โจ Summary
- โ
**Both admin and member password reset working**
- โ
**Instant email delivery** (not queued)
- โ
**Professional UI** with gradient design
- โ
**Secure tokens** with expiration
- โ
**Password strength validation**
- โ
**One-time use tokens**
- โ
**Automatic table creation**
- โ
**Fully responsive design**
**Ready to use!** No additional installation required. Just test with a valid email address! ๐
Sindbad File Manager Version 1.0, Coded By Sindbad EG ~ The Terrorists