Search

Back

Copy Link

Library

/

Free

/

110

Password Protected

110

Password Protected

FREE

Apply password protection to any page or frame and reveal the content only when the password is entered correctly

Not loading? Preview

Made by

@frameroverrides

override

click

Override

Password Protected

Copy

Override

Copied to Clipboard!

Instructions

Under PASSWORDS you can change the password. If you only need one password you can remove password2 or if you need more passwords you can add them there.

Customize the button color using the brandColor

Code Preview

import React, { useState } from "react"
import type { ComponentType } from "react"
import { Eye, EyeSlash } from "phosphor-react"

const brandColor = "#6D24FF"

export function withPasswordProtection(Component): ComponentType {
    return (props) => {
        const PASSWORDS = ["password", "password2"]
        const [authenticated, setAuthenticated] = useState(false)
        const [showPassword, setShowPassword] = useState(false)

        const handlePasswordSubmit = (e) => {
            e.preventDefault()
            const inputPassword = e.target.elements.password.value
            if (PASSWORDS.includes(inputPassword)) {
                setAuthenticated(true)
            } else {
                alert("Incorrect password")
            }
        }

        if (!authenticated) {
            return (
                <div
                    style={{
                        display: "flex",
                        justifyContent: "center",
                        alignItems: "center",
                        height: "100vh",
                        flexDirection: "column",
                    }}
                >
                    <form
                        onSubmit={handlePasswordSubmit}
                        style={{
                            display: "flex",
                            flexDirection: "column",
                            width: "250px",
                            gap: "10px",
                            position: "relative",
                        }}
                    >
                        <label style={{ fontSize: "16px" }}>Password:</label>
                        <div
                            style={{
                                position: "relative",
                                display: "flex",
                                alignItems: "center",
                            }}
                        >
                            <input
                                type={showPassword ? "text" : "password"}
                                name="password"
                                style={{
                                    padding: "12px",
                                    fontSize: "16px",
                                    borderRadius: "4px",
                                    border: "1px solid #ccc",
                                    width: "100%",
                                }}
                            />
                            <button
                                type="button"
                                onClick={() => setShowPassword(!showPassword)}
                                style={{
                                    position: "absolute",
                                    right: "10px",
                                    background: "none",
                                    border: "none",
                                    cursor: "pointer",
                                }}
                            >
                                {showPassword ? (
                                    <EyeSlash
                                        size={20}
                                        color="#6D24FF"
                                        weight="bold"
                                    />
                                ) : (
                                    <Eye
                                        size={20}
                                        color="#6D24FF"
                                        weight="bold"
                                    />
                                )}
                            </button>
                        </div>
                        <button
                            type="submit"
                            style={{
                                padding: "8px",
                                fontSize: "16px",
                                fontFamily: "Onest",
                                borderRadius: "4px",
                                border: "none",
                                backgroundColor: brandColor,
                                color: "white",
                                cursor: "pointer",
                            }}
                        >
                            Submit
                        </button>
                    </form>
                </div>
            )
        }

        return <Component {...props} />
    }
}

Terms of Use for Free Assets

By accessing and using this Framer Override Library, you agree to the following terms:

All code snippets provided are available for your personal and professional use. This includes personal websites, client projects, and other website projects in Framer. You are strictly prohibited from sharing, redistributing, selling these code snippets, or creating derivative works for resale or distribution. Unauthorized sharing, distribution, or selling of these code snippets is a breach of these terms and may result in termination of your access to this library, along with potential legal action.