INTRODUCTION TO JAVA LOGIN/SIGNUP FORMS
Login and signup forms are fundamental components of most applications. They serve as the gateway for user authentication and registration. Below I've created 10 distinct types of forms, each designed for different use cases and security requirements.
1. BASIC CONSOLE LOGIN FORM
Purpose: Simple text-based authentication for command-line applications
import java.util.Scanner;
public class BasicConsoleLogin {
private static final String VALID_USERNAME = "admin";
private static final String VALID_PASSWORD = "password123";
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.println("=== BASIC CONSOLE LOGIN FORM ===");
System.out.print("Username: ");
String username = scanner.nextLine();
System.out.print("Password: ");
String password = scanner.nextLine();
if (username.equals(VALID_USERNAME) && password.equals(VALID_PASSWORD)) {
System.out.println("✓ Login successful! Welcome " + username);
} else {
System.out.println("✗ Invalid username or password");
}
scanner.close();
}
}
Features:
- Simple text-based interface
- Hardcoded credentials for demonstration
- Immediate feedback on login attempt
- No external dependencies
2. PASSWORD STRENGTH CHECKER SIGNUP
Purpose: Ensures users create strong passwords during registration
import java.util.Scanner;
import java.util.regex.Pattern;
public class PasswordStrengthSignup {
static class User {
String username;
String password;
String email;
User(String username, String password, String email) {
this.username = username;
this.password = password;
this.email = email;
}
}
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.println("=== PASSWORD STRENGTH CHECKER SIGNUP ===");
System.out.println("Password must contain: uppercase, lowercase, number, special char, min 8 chars");
System.out.print("Username: ");
String username = scanner.nextLine();
System.out.print("Email: ");
String email = scanner.nextLine();
String password;
while (true) {
System.out.print("Password: ");
password = scanner.nextLine();
String strength = checkPasswordStrength(password);
System.out.println("Password strength: " + strength);
if (strength.equals("STRONG")) {
System.out.println("✓ Password accepted!");
break;
} else {
System.out.println("✗ Please choose a stronger password");
}
}
User newUser = new User(username, password, email);
System.out.println("\n✓ Signup successful for: " + newUser.username);
scanner.close();
}
private static String checkPasswordStrength(String password) {
boolean hasUpper = Pattern.compile("[A-Z]").matcher(password).find();
boolean hasLower = Pattern.compile("[a-z]").matcher(password).find();
boolean hasDigit = Pattern.compile("[0-9]").matcher(password).find();
boolean hasSpecial = Pattern.compile("[!@#$%^&*()_+\\-=\\[\\]{};':\"\\\\|,.<>/?]").matcher(password).find();
boolean lengthValid = password.length() >= 8;
if (hasUpper && hasLower && hasDigit && hasSpecial && lengthValid) {
return "STRONG";
} else if ((hasUpper || hasLower) && hasDigit && password.length() >= 6) {
return "MEDIUM";
} else {
return "WEAK";
}
}
}
Features:
- Password strength meter
- Real-time password validation
- Multiple password criteria checking
- Educational feedback for users
3. 2-FACTOR AUTHENTICATION LOGIN
Purpose: Enhanced security with OTP verification
import java.util.Scanner;
import java.util.Random;
public class TwoFactorAuthLogin {
private static final String VALID_USERNAME = "john_doe";
private static final String VALID_PASSWORD = "secure123";
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
Random random = new Random();
System.out.println("=== 2-FACTOR AUTHENTICATION LOGIN ===");
System.out.print("Username: ");
String username = scanner.nextLine();
System.out.print("Password: ");
String password = scanner.nextLine();
if (username.equals(VALID_USERNAME) && password.equals(VALID_PASSWORD)) {
// Generate 2FA code
int otp = 100000 + random.nextInt(900000);
System.out.println("\n📱 2FA Code sent to your phone: " + otp);
System.out.print("Enter 2FA code: ");
int enteredOTP = scanner.nextInt();
if (enteredOTP == otp) {
System.out.println("✓ 2FA verified! Login successful!");
} else {
System.out.println("✗ Invalid 2FA code");
}
} else {
System.out.println("✗ Invalid credentials");
}
scanner.close();
}
}
Features:
- Two-step verification process
- Simulated OTP generation
- Extra security layer
- Real-world authentication simulation
4. BIOMETRIC SIMULATION LOGIN
Purpose: Demonstrates biometric authentication concept
import java.util.Scanner;
import java.util.HashMap;
public class BiometricSimulationLogin {
private static HashMap<String, String> fingerprintDB = new HashMap<>();
static {
// Simulated fingerprint hashes
fingerprintDB.put("john_finger", "a1b2c3d4e5");
fingerprintDB.put("jane_finger", "f6g7h8i9j0");
}
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.println("=== BIOMETRIC SIMULATION LOGIN ===");
System.out.println("Place your finger on the scanner...");
System.out.print("Enter fingerprint ID: ");
String fingerprintId = scanner.nextLine();
System.out.print("Simulating fingerprint scan...\n");
simulateDelay();
if (fingerprintDB.containsKey(fingerprintId)) {
System.out.println("✓ Fingerprint matched! Access granted!");
System.out.println("Welcome, user: " + fingerprintId);
} else {
System.out.println("✗ Fingerprint not recognized");
System.out.println("✗ Access denied");
}
scanner.close();
}
private static void simulateDelay() {
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
Features:
- Simulated biometric verification
- Delay simulation for realism
- HashMap storage for fingerprints
- Contactless authentication concept
5. SOCIAL MEDIA STYLE LOGIN
Purpose: Modern login with "Remember Me" and social options
import java.util.Scanner;
import java.util.HashMap;
public class SocialMediaStyleLogin {
private static HashMap<String, String> users = new HashMap<>();
static {
users.put("[email protected]", "pass123");
}
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.println("=== SOCIAL MEDIA STYLE LOGIN ===");
System.out.println("Login with:");
System.out.println("1. Email/Password");
System.out.println("2. Google");
System.out.println("3. Facebook");
System.out.println("4. Twitter");
System.out.print("Choose option (1-4): ");
int choice = scanner.nextInt();
scanner.nextLine(); // consume newline
switch(choice) {
case 1:
emailPasswordLogin(scanner);
break;
case 2:
System.out.println("✓ Redirecting to Google login...");
break;
case 3:
System.out.println("✓ Redirecting to Facebook login...");
break;
case 4:
System.out.println("✓ Redirecting to Twitter login...");
break;
default:
System.out.println("✗ Invalid option");
}
scanner.close();
}
private static void emailPasswordLogin(Scanner scanner) {
System.out.print("Email: ");
String email = scanner.nextLine();
System.out.print("Password: ");
String password = scanner.nextLine();
System.out.print("Remember me? (yes/no): ");
String remember = scanner.nextLine();
if (users.containsKey(email) && users.get(email).equals(password)) {
System.out.println("✓ Login successful!");
if (remember.equalsIgnoreCase("yes")) {
System.out.println("✓ Session will be remembered");
}
} else {
System.out.println("✗ Invalid credentials");
}
}
}
Features:
- Multiple login options
- "Remember Me" functionality
- Modern UI approach
- Social media integration simulation
6. REGISTRATION WITH EMAIL VERIFICATION
Purpose: Email confirmation during signup
import java.util.Scanner;
import java.util.Random;
public class EmailVerificationSignup {
static class PendingUser {
String username;
String email;
String password;
int verificationCode;
PendingUser(String username, String email, String password, int code) {
this.username = username;
this.email = email;
this.password = password;
this.verificationCode = code;
}
}
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
Random random = new Random();
System.out.println("=== EMAIL VERIFICATION SIGNUP ===");
System.out.print("Username: ");
String username = scanner.nextLine();
System.out.print("Email: ");
String email = scanner.nextLine();
System.out.print("Password: ");
String password = scanner.nextLine();
// Generate verification code
int verificationCode = 100000 + random.nextInt(900000);
PendingUser pendingUser = new PendingUser(username, email, password, verificationCode);
System.out.println("\n📧 Verification code sent to: " + email);
System.out.println("Code: " + verificationCode); // Simulating email
System.out.print("\nEnter verification code: ");
int enteredCode = scanner.nextInt();
if (enteredCode == pendingUser.verificationCode) {
System.out.println("✓ Email verified! Registration complete!");
System.out.println("Welcome, " + pendingUser.username);
} else {
System.out.println("✗ Invalid verification code");
}
scanner.close();
}
}
Features:
- Email verification simulation
- Temporary user storage
- Code-based confirmation
- Prevents fake registrations
7. PIN-BASED LOGIN SYSTEM
Purpose: Quick access with numeric PIN (like ATM)
import java.util.Scanner;
import java.util.HashMap;
public class PinBasedLogin {
private static HashMap<String, Integer> pinDatabase = new HashMap<>();
private static HashMap<String, Double> accountBalances = new HashMap<>();
static {
pinDatabase.put("1234567890", 1234); // Phone number -> PIN
accountBalances.put("1234567890", 5000.00);
}
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int attempts = 0;
final int MAX_ATTEMPTS = 3;
System.out.println("=== PIN-BASED LOGIN SYSTEM ===");
System.out.print("Enter phone number: ");
String phoneNumber = scanner.nextLine();
while (attempts < MAX_ATTEMPTS) {
System.out.print("Enter 4-digit PIN: ");
int enteredPin = scanner.nextInt();
if (pinDatabase.containsKey(phoneNumber) &&
pinDatabase.get(phoneNumber) == enteredPin) {
System.out.println("✓ Login successful!");
System.out.println("Account balance: $" +
accountBalances.get(phoneNumber));
break;
} else {
attempts++;
if (attempts < MAX_ATTEMPTS) {
System.out.println("✗ Invalid PIN. Attempts left: " +
(MAX_ATTEMPTS - attempts));
} else {
System.out.println("✗ Account locked. Contact support.");
}
}
}
scanner.close();
}
}
Features:
- Numeric PIN authentication
- Attempt limiting
- Account lockout after max attempts
- Fast, simple access
8. GUEST LOGIN OPTION
Purpose: Allows temporary access without registration
import java.util.Scanner;
import java.util.UUID;
public class GuestLoginOption {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.println("=== GUEST LOGIN OPTION ===");
System.out.println("1. Create Account");
System.out.println("2. Login");
System.out.println("3. Continue as Guest");
System.out.print("Choose option: ");
int choice = scanner.nextInt();
switch(choice) {
case 1:
createAccount(scanner);
break;
case 2:
login(scanner);
break;
case 3:
guestAccess();
break;
default:
System.out.println("Invalid option");
}
scanner.close();
}
private static void createAccount(Scanner scanner) {
scanner.nextLine(); // consume newline
System.out.print("Username: ");
String username = scanner.nextLine();
System.out.print("Email: ");
String email = scanner.nextLine();
System.out.print("Password: ");
String password = scanner.nextLine();
System.out.println("✓ Account created for: " + username);
}
private static void login(Scanner scanner) {
scanner.nextLine(); // consume newline
System.out.print("Username: ");
String username = scanner.nextLine();
System.out.print("Password: ");
String password = scanner.nextLine();
System.out.println("✓ Welcome back, " + username);
}
private static void guestAccess() {
String guestId = UUID.randomUUID().toString().substring(0, 8);
System.out.println("✓ Continuing as Guest");
System.out.println("Your temporary ID: " + guestId);
System.out.println("Note: Guest data will not be saved");
}
}
Features:
- Multiple access options
- Temporary guest accounts
- UUID generation for guests
- No commitment required
9. PASSWORD RECOVERY SYSTEM
Purpose: Helps users reset forgotten passwords
import java.util.Scanner;
import java.util.HashMap;
public class PasswordRecoverySystem {
private static HashMap<String, User> userDatabase = new HashMap<>();
static class User {
String username;
String password;
String securityQuestion;
String securityAnswer;
User(String username, String password, String question, String answer) {
this.username = username;
this.password = password;
this.securityQuestion = question;
this.securityAnswer = answer.toLowerCase();
}
}
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
// Sample user
userDatabase.put("[email protected]", new User("john_doe", "oldpass123",
"What is your pet's name?", "fluffy"));
System.out.println("=== PASSWORD RECOVERY SYSTEM ===");
System.out.print("Enter your email: ");
String email = scanner.nextLine();
if (userDatabase.containsKey(email)) {
User user = userDatabase.get(email);
System.out.println("\nSecurity Question: " + user.securityQuestion);
System.out.print("Answer: ");
String answer = scanner.nextLine().toLowerCase();
if (answer.equals(user.securityAnswer)) {
System.out.print("\nEnter new password: ");
String newPassword = scanner.nextLine();
user.password = newPassword;
System.out.println("✓ Password updated successfully!");
} else {
System.out.println("✗ Incorrect answer");
}
} else {
System.out.println("✗ Email not found");
}
scanner.close();
}
}
Features:
- Security questions
- Password reset functionality
- Email verification
- User-friendly recovery process
10. MULTI-ROLE LOGIN SYSTEM
Purpose: Different access levels for different user types
import java.util.Scanner;
import java.util.HashMap;
public class MultiRoleLoginSystem {
private static HashMap<String, User> users = new HashMap<>();
static class User {
String username;
String password;
String role;
User(String username, String password, String role) {
this.username = username;
this.password = password;
this.role = role;
}
}
static {
users.put("admin", new User("admin", "admin123", "ADMIN"));
users.put("manager", new User("manager", "mgr123", "MANAGER"));
users.put("employee", new User("employee", "emp123", "EMPLOYEE"));
users.put("guest", new User("guest", "guest123", "GUEST"));
}
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.println("=== MULTI-ROLE LOGIN SYSTEM ===");
System.out.print("Username: ");
String username = scanner.nextLine();
System.out.print("Password: ");
String password = scanner.nextLine();
if (users.containsKey(username)) {
User user = users.get(username);
if (user.password.equals(password)) {
System.out.println("✓ Login successful!");
System.out.println("Role: " + user.role);
showRoleMenu(user.role);
} else {
System.out.println("✗ Invalid password");
}
} else {
System.out.println("✗ User not found");
}
scanner.close();
}
private static void showRoleMenu(String role) {
System.out.println("\n=== ACCESSIBLE FEATURES ===");
switch(role) {
case "ADMIN":
System.out.println("• Full system access");
System.out.println("• User management");
System.out.println("• Configuration");
System.out.println("• Reports");
break;
case "MANAGER":
System.out.println("• Team overview");
System.out.println("• Approvals");
System.out.println("• Reports view");
break;
case "EMPLOYEE":
System.out.println("• Personal dashboard");
System.out.println("• Time tracking");
System.out.println("• Tasks");
break;
case "GUEST":
System.out.println("• Read-only access");
System.out.println("• Public information");
break;
}
}
}
Features:
- Role-based access control
- Different permission levels
- Customized menus per role
- Scalable user management
SUMMARY OF FEATURES
| Form Type | Primary Feature | Best Used For |
|---|---|---|
| Basic Console | Simple authentication | Learning, testing |
| Password Strength | Security education | User registration |
| 2-Factor Auth | Enhanced security | Banking, sensitive data |
| Biometric | Modern authentication | High-security apps |
| Social Media | Multiple login options | Consumer apps |
| Email Verification | Account confirmation | Web services |
| PIN-based | Quick access | Mobile apps, ATMs |
| Guest Login | Temporary access | E-commerce, demos |
| Password Recovery | User convenience | All applications |
| Multi-role | Access control | Enterprise systems |
Each form serves different purposes and can be combined or modified based on specific application requirements. The key is to balance security with user convenience while providing the appropriate level of access control.