Skip to content

Privacy-first password manager with built-in email aliasing. Fully encrypted and self-hostable.

Add password visibility toggle to browser extension login/unlock (#1169)

Leendert de Borstc2b824c31e01
diff --git a/apps/browser-extension/src/entrypoints/popup/components/Icons/HeaderIcons.tsx b/apps/browser-extension/src/entrypoints/popup/components/Icons/HeaderIcons.tsx
index 5887ac218..7ab877be1 100644
--- a/apps/browser-extension/src/entrypoints/popup/components/Icons/HeaderIcons.tsx
+++ b/apps/browser-extension/src/entrypoints/popup/components/Icons/HeaderIcons.tsx
@@ -9,7 +9,9 @@ export enum HeaderIconType {
EXTERNAL_LINK = 'external_link',
SAVE = 'save',
PLUS = 'plus',
- TAB = 'tab'
+ TAB = 'tab',
+ EYE = 'eye',
+ EYE_OFF = 'eye_off'
}
type HeaderIconProps = {
@@ -167,6 +169,44 @@ export const HeaderIcon: React.FC<HeaderIconProps> = ({ type, className = 'w-5 h
d="M8 5a2 2 0 012-2h4a2 2 0 012 2v2H8V5z"
/>
</svg>
+ ),
+ [HeaderIconType.EYE]: (
+ <svg
+ className={className}
+ fill="none"
+ stroke="currentColor"
+ viewBox="0 0 24 24"
+ xmlns="http://www.w3.org/2000/svg"
+ >
+ <path
+ strokeLinecap="round"
+ strokeLinejoin="round"
+ strokeWidth={2}
+ d="M15 12a3 3 0 11-6 0 3 3 0 016 0z"
+ />
+ <path
+ strokeLinecap="round"
+ strokeLinejoin="round"
+ strokeWidth={2}
+ d="M2.458 12C3.732 7.943 7.523 5 12 5c4.478 0 8.268 2.943 9.542 7-1.274 4.057-5.064 7-9.542 7-4.477 0-8.268-2.943-9.542-7z"
+ />
+ </svg>
+ ),
+ [HeaderIconType.EYE_OFF]: (
+ <svg
+ className={className}
+ fill="none"
+ stroke="currentColor"
+ viewBox="0 0 24 24"
+ xmlns="http://www.w3.org/2000/svg"
+ >
+ <path
+ strokeLinecap="round"
+ strokeLinejoin="round"
+ strokeWidth={2}
+ d="M13.875 18.825A10.05 10.05 0 0112 19c-4.478 0-8.268-2.943-9.543-7a9.97 9.97 0 011.563-3.029m5.858.908a3 3 0 114.243 4.243M9.878 9.878l4.242 4.242M9.88 9.88l-3.29-3.29m7.532 7.532l3.29 3.29M3 3l3.59 3.59m0 0A9.953 9.953 0 0112 5c4.478 0 8.268 2.943 9.543 7a10.025 10.025 0 01-4.132 5.411m0 0L21 21"
+ />
+ </svg>
)
};
diff --git a/apps/browser-extension/src/entrypoints/popup/pages/auth/Login.tsx b/apps/browser-extension/src/entrypoints/popup/pages/auth/Login.tsx
index d2605ac5c..861c6a81e 100644
--- a/apps/browser-extension/src/entrypoints/popup/pages/auth/Login.tsx
+++ b/apps/browser-extension/src/entrypoints/popup/pages/auth/Login.tsx
@@ -6,7 +6,7 @@ import { useNavigate } from 'react-router-dom';
import Button from '@/entrypoints/popup/components/Button';
import HeaderButton from '@/entrypoints/popup/components/HeaderButton';
-import { HeaderIconType } from '@/entrypoints/popup/components/Icons/HeaderIcons';
+import { HeaderIcon, HeaderIconType } from '@/entrypoints/popup/components/Icons/HeaderIcons';
import LoginServerInfo from '@/entrypoints/popup/components/LoginServerInfo';
import { useAuth } from '@/entrypoints/popup/context/AuthContext';
import { useDb } from '@/entrypoints/popup/context/DbContext';
@@ -39,6 +39,7 @@ const Login: React.FC = () => {
});
const { showLoading, hideLoading, setIsInitialLoading } = useLoading();
const [rememberMe, setRememberMe] = useState(true);
+ const [showPassword, setShowPassword] = useState(false);
const [loginResponse, setLoginResponse] = useState<LoginResponse | null>(null);
const [passwordHashString, setPasswordHashString] = useState<string | null>(null);
const [passwordHashBase64, setPasswordHashBase64] = useState<string | null>(null);
@@ -379,16 +380,26 @@ const Login: React.FC = () => {
<label className="block text-gray-700 dark:text-gray-200 font-bold mb-2" htmlFor="password">
{t('auth.password')}
</label>
- <input
- className="shadow text-sm appearance-none border rounded w-full py-2 px-3 text-gray-700 dark:text-gray-200 dark:bg-gray-800 dark:border-gray-600 mb-3 leading-tight focus:outline-none focus:shadow-outline"
- id="password"
- type="password"
- name="password"
- placeholder={t('auth.passwordPlaceholder')}
- value={credentials.password}
- onChange={handleChange}
- required
- />
+ <div className="relative">
+ <input
+ className="shadow text-sm appearance-none border rounded w-full py-2 px-3 pr-10 text-gray-700 dark:text-gray-200 dark:bg-gray-800 dark:border-gray-600 mb-3 leading-tight focus:outline-none focus:shadow-outline"
+ id="password"
+ type={showPassword ? "text" : "password"}
+ name="password"
+ placeholder={t('auth.passwordPlaceholder')}
+ value={credentials.password}
+ onChange={handleChange}
+ required
+ />
+ <button
+ type="button"
+ className="absolute right-2 top-2 text-gray-500 hover:text-gray-700 dark:text-gray-400 dark:hover:text-gray-200"
+ onClick={() => setShowPassword(!showPassword)}
+ tabIndex={-1}
+ >
+ <HeaderIcon type={showPassword ? HeaderIconType.EYE_OFF : HeaderIconType.EYE} className="w-5 h-5 text-gray-400 dark:text-gray-500" />
+ </button>
+ </div>
</div>
<div className="mb-6">
<label className="flex items-center">
diff --git a/apps/browser-extension/src/entrypoints/popup/pages/auth/Unlock.tsx b/apps/browser-extension/src/entrypoints/popup/pages/auth/Unlock.tsx
index 35ecf44db..74978d485 100644
--- a/apps/browser-extension/src/entrypoints/popup/pages/auth/Unlock.tsx
+++ b/apps/browser-extension/src/entrypoints/popup/pages/auth/Unlock.tsx
@@ -6,7 +6,7 @@ import { useNavigate } from 'react-router-dom';
import Button from '@/entrypoints/popup/components/Button';
import HeaderButton from '@/entrypoints/popup/components/HeaderButton';
-import { HeaderIconType } from '@/entrypoints/popup/components/Icons/HeaderIcons';
+import { HeaderIcon, HeaderIconType } from '@/entrypoints/popup/components/Icons/HeaderIcons';
import { useAuth } from '@/entrypoints/popup/context/AuthContext';
import { useDb } from '@/entrypoints/popup/context/DbContext';
import { useHeaderButtons } from '@/entrypoints/popup/context/HeaderButtonsContext';
@@ -35,6 +35,7 @@ const Unlock: React.FC = () => {
const srpUtil = new SrpUtility(webApi);
const [password, setPassword] = useState('');
+ const [showPassword, setShowPassword] = useState(false);
const [error, setError] = useState<string | null>(null);
const { showLoading, hideLoading, setIsInitialLoading } = useLoading();
@@ -168,16 +169,26 @@ const Unlock: React.FC = () => {
<label className="block text-gray-700 dark:text-gray-200 font-bold mb-2" htmlFor="password">
{t('auth.masterPassword')}
</label>
- <input
- className="shadow appearance-none border rounded w-full py-2 px-3 text-gray-700 dark:text-gray-200 dark:bg-gray-800 dark:border-gray-600 mb-3 leading-tight focus:outline-none focus:shadow-outline"
- id="password"
- type="password"
- value={password}
- onChange={(e) => setPassword(e.target.value)}
- placeholder={t('auth.passwordPlaceholder')}
- required
- autoFocus
- />
+ <div className="relative">
+ <input
+ className="shadow appearance-none border rounded w-full py-2 px-3 pr-10 text-gray-700 dark:text-gray-200 dark:bg-gray-800 dark:border-gray-600 mb-3 leading-tight focus:outline-none focus:shadow-outline"
+ id="password"
+ type={showPassword ? "text" : "password"}
+ value={password}
+ onChange={(e) => setPassword(e.target.value)}
+ placeholder={t('auth.passwordPlaceholder')}
+ required
+ autoFocus
+ />
+ <button
+ type="button"
+ className="absolute right-2 top-2 text-gray-500 hover:text-gray-700 dark:text-gray-400 dark:hover:text-gray-200"
+ onClick={() => setShowPassword(!showPassword)}
+ tabIndex={-1}
+ >
+ <HeaderIcon type={showPassword ? HeaderIconType.EYE_OFF : HeaderIconType.EYE} className="w-5 h-5 text-gray-400 dark:text-gray-500" />
+ </button>
+ </div>
</div>
<Button type="submit">