Неоновая надёжность пароля

Индикатор надёжности пароля из неона. Он подсвечивает всю карточку своим цветом, а слабый пароль заставляет трубку искрить и гаснуть.

Введите 12345 и нажмите Enter, потом попробуйте Neon#42lamp.

Скачать

Что можно поменять

Поменяйте число, сохраните файл и обновите страницу, разница будет видна сразу.

RULES4 checks

Что делает пароль надёжным. Каждое выполненное правило зажигает ещё один сегмент. Добавляйте или убирайте регулярные выражения, чтобы поменять требования.

HUE4 colors

Цвет неона для 1, 2, 3 и 4 выполненных правил. Подойдут любые hex-цвета, вся карточка светится текущим.

< 3in submit

Сколько правил нужно выполнить, чтобы форма приняла пароль. Уменьшите, чтобы требования были мягче.

Как поставить на свой сайт

Поставьте на экран регистрации или смены пароля.

Комментарии в коде на английском, так файл понятен любому разработчику.

  1. CSS

    Вставьте в свой файл стилей или в тег <style> внутри <head>.

    /* --glow is set by the script to the current neon color, everything lit by the tube reads it */
    .neon-form { --glow: 255, 77, 94; --light: 0;
      position: relative; box-sizing: border-box; width: min(380px, 92vw); padding: 26px 24px 24px; border-radius: 26px; color: #F3F5F8;
      background:
        radial-gradient(120% 70% at 50% 62%, rgba(var(--glow), calc(var(--light) * .22)), transparent 60%),
        linear-gradient(#12161D, #0C0F14);
      border: 1px solid rgba(var(--glow), calc(.08 + var(--light) * .35));
      transition: border-color .25s ease; }
    /* the outer glow lives on its own layer so only its opacity animates, not a repainted box-shadow */
    .neon-form::after { content: ""; position: absolute; inset: 0; border-radius: inherit; pointer-events: none;
      box-shadow: 0 0 70px rgba(var(--glow), .35); opacity: var(--light); transition: opacity .25s cubic-bezier(.23, 1, .32, 1); }
    .neon-form h2 { margin: 0; font-size: 21px; letter-spacing: -.02em; }
    .neon-form .rules { margin: 4px 0 18px; font-size: 13px; color: #7A8290; }
    
    .neon-field { position: relative; }
    .neon-field input { width: 100%; box-sizing: border-box; height: 48px; padding: 0 44px 0 16px; border-radius: 12px; outline: none;
      background: #080A0E; color: #F3F5F8; font: 500 17px Menlo, monospace;
      border: 1px solid rgba(var(--glow), calc(.18 + var(--light) * .45)); }
    .neon-field button { position: absolute; right: 8px; top: 8px; width: 32px; height: 32px; border: 0; background: none; color: #7A8290; cursor: pointer; }
    .neon-form.shake .neon-field { animation: shake .45s cubic-bezier(.23, 1, .32, 1); }
    @keyframes shake { 20% { transform: translateX(-7px); } 40% { transform: translateX(6px); } 60% { transform: translateX(-4px); } 80% { transform: translateX(2px); } }
    
    /* the tube: four glass segments, the lit ones glow in the current color */
    .tube { position: relative; display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; margin: 18px 6px 8px; }
    .tube i { height: 9px; border-radius: 9px; background: #10141A; box-shadow: inset 0 0 0 1px rgba(255,255,255,.08); transition: background .08s, box-shadow .08s; }
    .tube i.on { background: rgb(var(--glow));
      box-shadow: 0 0 5px rgba(var(--glow), .9), 0 0 16px rgba(var(--glow), .5), 0 0 38px rgba(var(--glow), .35), inset 0 2px 0 rgba(255,255,255,.5); }
    .tube i.ignite { animation: ignite .22s steps(1); }
    @keyframes ignite { 0%, 40%, 80% { opacity: .15; } 20%, 60%, 100% { opacity: 1; } }
    .tube.sputter i.on { animation: sputter .5s steps(1) forwards; }
    @keyframes sputter { 0%, 30%, 55% { opacity: 1; filter: brightness(1.3); } 15%, 45%, 70% { opacity: .05; } 100% { opacity: 0; } }
    .spark { position: absolute; width: 3px; height: 3px; border-radius: 50%; background: #FFE3C4; box-shadow: 0 0 8px #FF6A4D; pointer-events: none; }
    
    .neon-label { min-height: 18px; margin: 0 6px 14px; font-size: 13px; font-weight: 600; color: rgb(var(--glow)); }
    .neon-form .go { width: 100%; height: 44px; border: 0; border-radius: 12px; font: 650 15px system-ui, sans-serif; cursor: pointer;
      background: #1A1F27; color: #8A93A1; transition: background .2s ease, color .2s ease, transform .16s cubic-bezier(.23, 1, .32, 1); }
    .neon-form .go:active { transform: scale(.97); }
    .neon-form.strong .go { background: rgb(108, 235, 217); color: #03201C; box-shadow: 0 0 26px rgba(108, 235, 217, .5); }
    
    @media (prefers-reduced-motion: reduce) { .tube i.ignite, .tube.sputter i.on, .neon-form.shake .neon-field { animation: none; } }
  2. HTML

    Поставьте в то место страницы, где должен быть эффект.

    <form class="neon-form" novalidate>
      <h2>Create a password</h2>
      <p class="rules">10+ characters, a capital, a digit, a symbol</p>
      <div class="neon-field">
        <input id="pw" type="password" autocomplete="new-password" aria-describedby="neon-label" placeholder="Type a password">
        <button type="button" class="reveal" aria-label="Show password">
          <svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8"><path d="M2 12s3.6-7 10-7 10 7 10 7-3.6 7-10 7S2 12 2 12Z"/><circle cx="12" cy="12" r="3"/></svg>
        </button>
      </div>
      <div class="tube" aria-hidden="true"><i></i><i></i><i></i><i></i></div>
      <div class="neon-label" id="neon-label" aria-live="polite"></div>
      <button class="go" type="submit">Continue</button>
    </form>
  3. JavaScript

    Вставьте перед закрывающим тегом </body>, внутри <script></script>.

    // the rules that make a password strong, and the neon color for 1, 2, 3 and 4 of them
    const RULES = [/.{10,}/, /[A-Z]/, /\d/, /\W/];
    const HUE = ['#FF4D5E', '#FF9F43', '#FFD166', '#6CEBD9'];
    const LABELS = ['', 'Weak', 'Getting there', 'Almost', 'Strong password'];
    
    const score = pw => RULES.filter(r => r.test(pw)).length;
    
    const form = document.querySelector('.neon-form');
    const input = form.querySelector('#pw');
    const label = form.querySelector('.neon-label');
    const segs = [...form.querySelectorAll('.tube i')];
    const hex = h => [1, 3, 5].map(i => parseInt(h.slice(i, i + 2), 16)).join(', ');
    
    const tube = {
      lit: 0,
      light(n, hue) {
        form.style.setProperty('--glow', hex(hue[Math.max(0, n - 1)]));
        form.style.setProperty('--light', n / 4);
        segs.forEach((s, i) => {
          const on = i < n;
          if (on && i >= this.lit) { s.classList.remove('ignite'); void s.offsetWidth; s.classList.add('ignite'); }
          s.classList.toggle('on', on);
        });
        this.lit = n;
        form.classList.toggle('strong', n === 4);
        label.textContent = LABELS[n];
      },
      sputter() {
        const box = form.querySelector('.tube');
        box.classList.add('sputter'); form.classList.add('shake');
        label.textContent = 'Too easy to guess';
        const r = segs[0].getBoundingClientRect(), b = box.getBoundingClientRect();
        for (let i = 0; i < 16; i++) {                     // sparks fly out of the first segment
          const s = document.createElement('span'); s.className = 'spark';
          s.style.left = (r.left - b.left + Math.random() * r.width) + 'px'; s.style.top = '3px';
          box.append(s);
          const a = -Math.PI * (.15 + .7 * Math.random()), v = 90 + 140 * Math.random();
          s.animate([{ transform: 'translate(0,0)', opacity: 1 },
                     { transform: `translate(${Math.cos(a) * v * .8}px, ${Math.sin(a) * v * .8 + 150}px)`, opacity: 0 }],
                    { duration: 600 + 400 * Math.random(), easing: 'cubic-bezier(.2,.6,.4,1)' }).onfinish = () => s.remove();
        }
        setTimeout(() => { box.classList.remove('sputter'); form.classList.remove('shake'); input.value = ''; this.light(0, HUE); input.focus(); }, 900);
      },
    };
    
    input.addEventListener('input', () => {
      const pw = input.value;
      tube.light(score(pw), HUE);
    });
    
    form.querySelector('.reveal').addEventListener('click', () => {
      input.type = input.type === 'password' ? 'text' : 'password';
    });
    
    form.addEventListener('submit', e => {
      e.preventDefault();
      const pw = input.value;
      if (score(pw) < 3) tube.sputter();
      else form.querySelector('.go').textContent = 'Password saved';   // a real server request goes here
    });
    
    tube.light(0, HUE);

Подключение к серверу

В обработчике отправки ветка else это место для настоящего запроса. Отправляйте туда пароль вместо смены текста кнопки.

Полезно знать

Tilda, Webflow, WordPress

Нажмите «Скопировать весь код» вверху и вставьте его в один HTML-блок.

Tilda

Добавить блок, Другое, T123 HTML-код. Вставьте и сохраните. Проверяйте на опубликованной странице, в редакторе скрипты не запускаются.

Webflow

Панель Add, Embed. Вставьте и нажмите Save & Close. Свой код работает на опубликованном сайте.

WordPress

Добавить блок, Произвольный HTML. Вставьте и нажмите «Обновить».

Ещё в разделе «Вход и формы»

Все
Скопировано