πŸ” Java Secure Login GUI using SHA-256 | Eye Toggle GUI – FuzzuTech

 Demo :


Click Video πŸ‘‡πŸ‘‡πŸ‘‡


























πŸ“Œ Features

  • Embedded YouTube Short

  • 1 Screenshot of GUI

  • Code Highlights (MessageDigest, JPasswordField, ActionListener)

  • Feature List: SHA-256 hash, password visibility toggle, dark UI

  • CTA: Download Code, Try GUI


Code :


import javax.swing.*;

import java.awt.*;

import java.awt.event.*;

import java.security.MessageDigest;


public class SecureLogin extends JFrame {

    private JTextField usernameField;

    private JPasswordField passwordField;

    private JButton eyeButton;

    private boolean passwordVisible = false;


    public SecureLogin() {

        setTitle("πŸ” Secure Login – FuzzuTech");

        setSize(400, 300);

        setLocationRelativeTo(null);

        setDefaultCloseOperation(EXIT_ON_CLOSE);

        setLayout(null);


        // πŸ–€ Modern Dark Theme Colors

        getContentPane().setBackground(new Color(30, 30, 30));


        JLabel titleLabel = new JLabel("Fuzzu Secure Login");

        titleLabel.setForeground(Color.WHITE);

        titleLabel.setFont(new Font("Segoe UI", Font.BOLD, 18));

        titleLabel.setBounds(100, 20, 250, 30);

        add(titleLabel);


        JLabel userLabel = new JLabel("Username:");

        userLabel.setForeground(Color.WHITE);

        userLabel.setBounds(50, 70, 100, 25);

        add(userLabel);


        usernameField = new JTextField();

        usernameField.setBounds(150, 70, 180, 25);

        add(usernameField);


        JLabel passLabel = new JLabel("Password:");

        passLabel.setForeground(Color.WHITE);

        passLabel.setBounds(50, 110, 100, 25);

        add(passLabel);


        passwordField = new JPasswordField();

        passwordField.setBounds(150, 110, 140, 25);

        add(passwordField);


        // πŸ‘ Eye Toggle Button

        eyeButton = new JButton("πŸ‘");

        eyeButton.setBounds(295, 110, 40, 25);

        eyeButton.setBackground(Color.DARK_GRAY);

        eyeButton.setForeground(Color.WHITE);

        eyeButton.setFocusPainted(false);

        eyeButton.addActionListener(e -> togglePassword());

        add(eyeButton);


        JButton loginBtn = new JButton("Login");

        loginBtn.setBounds(150, 160, 120, 30);

        loginBtn.setBackground(new Color(76, 175, 80));

        loginBtn.setForeground(Color.WHITE);

        loginBtn.setFont(new Font("Segoe UI", Font.BOLD, 14));

        loginBtn.setFocusPainted(false);

        loginBtn.addActionListener(e -> loginAction());

        add(loginBtn);

    }


    // 🧠 SHA-256 Password Hashing Function

    private String hashPassword(String password) {

        try {

            MessageDigest md = MessageDigest.getInstance("SHA-256");

            byte[] hash = md.digest(password.getBytes("UTF-8"));

            StringBuilder sb = new StringBuilder();

            for (byte b : hash)

                sb.append(String.format("%02x", b));

            return sb.toString();

        } catch (Exception e) {

            return null;

        }

    }


    // πŸ” Login Function with Hashed Check

    private void loginAction() {

        String user = usernameField.getText();

        String pass = new String(passwordField.getPassword());

        String hashed = hashPassword(pass);


        if (user.equals("admin") && hashed.equals(hashPassword("admin123"))) {

            JOptionPane.showMessageDialog(this, "Welcome " + user + "!", "Success", JOptionPane.INFORMATION_MESSAGE);

        } else {

            JOptionPane.showMessageDialog(this, "Invalid credentials!", "Error", JOptionPane.ERROR_MESSAGE);

        }

    }


    // πŸ‘ Toggle Password Visibility

    private void togglePassword() {

        passwordVisible = !passwordVisible;

        passwordField.setEchoChar(passwordVisible ? (char) 0 : '•');

        eyeButton.setText(passwordVisible ? "πŸ™ˆ" : "πŸ‘");

    }


    public static void main(String[] args) {

        SwingUtilities.invokeLater(() -> new SecureLogin().setVisible(true));

    }

}

Comments

Popular posts from this blog

πŸš€ Simple Login & Registration System in Python Tkinter πŸ“±

πŸš€ Create a Python Screen Recorder with Audio (Complete Code)

Python IP Tracker App with GUI | Track IP Location Real-Time! (Working Project)