diff --git a/Docs/Investigations/TwoFactorOtpStyling-20261125.md b/Docs/Investigations/TwoFactorOtpStyling-20261125.md new file mode 100644 index 00000000..d69db6ef --- /dev/null +++ b/Docs/Investigations/TwoFactorOtpStyling-20261125.md @@ -0,0 +1,54 @@ +# Two-factor code entry styling — 25 November 2026 + +The ordinary-browser `/Account/TwoFactor` view loaded Bootstrap input styling but +not its component geometry: `_PublicLayout` marks plotline-theme.css `media="not +all"`, and public-auth-theme.js only enables that legacy stylesheet in installed +windows. All existing `.two-factor-inputs` / `.two-factor-digit` rules lived there. +Chromium confirmed the stylesheet loaded successfully but did not participate in +the cascade. Bootstrap's display:block/width:100% then produced six stacked inputs. +This is a loading/scope regression, not missing markup or an input-script failure. + +The correction restores OTP geometry in the already-loaded public-site.css, +inside its existing html[data-site-theme="public"] scope. Six equal shrinking +square tracks, centred digits and spacing above/below the row work independently +of the installed-window theme. Existing public colours, focus ring, page layout, +buttons, recovery link, typography outside the digits and all form-control rules +remain unchanged. Installed-window legacy styles remain responsible for that mode. +No Razor, JavaScript, authentication/security or database structure was changed. + +Actual compiled Razor/controller/layout rendering was exercised on an isolated +loopback host. Its test-only IAuthService supplies a synthetic pending challenge; +it cannot authenticate a user, perform TOTP operations or connect to a real DB. +All hosted workers and outbound HTTP were disabled. This is rendered-page evidence, +not a genuine account login or authenticator verification claim. The fixture was +not installed into Development or Production. + +Chromium checks at 1440, 390 and 320 pixels passed: one row, equal squares and gaps, +centred text, inherited visible focus, no horizontal overflow and button separation. +Inputs measured 56px, approximately 44.5px and 33.7px respectively. Before-and-after +screenshots were visually inspected, including digits at the narrowest width. +Advancement, numeric filtering, complete-code paste, backspace, Tab/Shift+Tab/arrows, +existing accessibility/mobile attributes, automatic POST payload and antiforgery +presence passed. Submission of empty Code exercised the real server-side required +validation. Complete-code submissions were intercepted in the browser to avoid +performing any authentication operation. + +EnableTwoFactor uses a separate single `Code` input under ManageAccount, not these +component classes or public layout. Its actual Razor view was also rendered with +a display-only model; the verification input remains full-width. No setup or +recovery-code logic was touched. + +Reproduce browser checks with `OTP_VISUAL_URL=http://127.0.0.1:5282 node +PlotLine.Tests/Browser/two-factor-otp.cjs` against the loopback Razor fixture retained +privately at `/home/nick/otp-style-20261125/host`. The script refuses non-loopback +hosts. Screenshots and measured geometry are in +[the visual evidence directory](../Testing/TwoFactorOtp-20261125/after-390.png). + +| Viewport | Before | After | +| --- | --- | --- | +| Desktop 1440px | [Before](../Testing/TwoFactorOtp-20261125/before-1440.png) | [After](../Testing/TwoFactorOtp-20261125/after-1440.png) | +| Mobile 390px | [Before](../Testing/TwoFactorOtp-20261125/before-390.png) | [After](../Testing/TwoFactorOtp-20261125/after-390.png) | +| Narrow 320px | [Before](../Testing/TwoFactorOtp-20261125/before-320.png) | [After](../Testing/TwoFactorOtp-20261125/after-320.png) | + +Deployment is Development only; its resulting release identity and checks are +recorded separately after activation. Production is not changed by this task. diff --git a/Docs/Testing/TwoFactorOtp-20261125/after-1440.png b/Docs/Testing/TwoFactorOtp-20261125/after-1440.png new file mode 100644 index 00000000..e2f23425 Binary files /dev/null and b/Docs/Testing/TwoFactorOtp-20261125/after-1440.png differ diff --git a/Docs/Testing/TwoFactorOtp-20261125/after-320.png b/Docs/Testing/TwoFactorOtp-20261125/after-320.png new file mode 100644 index 00000000..6ea6caa7 Binary files /dev/null and b/Docs/Testing/TwoFactorOtp-20261125/after-320.png differ diff --git a/Docs/Testing/TwoFactorOtp-20261125/after-390.png b/Docs/Testing/TwoFactorOtp-20261125/after-390.png new file mode 100644 index 00000000..0bff9543 Binary files /dev/null and b/Docs/Testing/TwoFactorOtp-20261125/after-390.png differ diff --git a/Docs/Testing/TwoFactorOtp-20261125/after-geometry.json b/Docs/Testing/TwoFactorOtp-20261125/after-geometry.json new file mode 100644 index 00000000..dfae8e91 --- /dev/null +++ b/Docs/Testing/TwoFactorOtp-20261125/after-geometry.json @@ -0,0 +1,146 @@ +{ + "320": { + "boxes": [ + { + "x": 47, + "y": 446.5, + "width": 33.65625, + "height": 33.65625, + "textAlign": "center" + }, + { + "x": 85.453125, + "y": 446.5, + "width": 33.671875, + "height": 33.671875, + "textAlign": "center" + }, + { + "x": 123.921875, + "y": 446.5, + "width": 33.671875, + "height": 33.671875, + "textAlign": "center" + }, + { + "x": 162.390625, + "y": 446.5, + "width": 33.671875, + "height": 33.671875, + "textAlign": "center" + }, + { + "x": 200.859375, + "y": 446.5, + "width": 33.671875, + "height": 33.671875, + "textAlign": "center" + }, + { + "x": 239.328125, + "y": 446.5, + "width": 33.671875, + "height": 33.671875, + "textAlign": "center" + } + ], + "media": "not all", + "overflow": false + }, + "390": { + "boxes": [ + { + "x": 47, + "y": 446.5, + "width": 44.453125, + "height": 44.453125, + "textAlign": "center" + }, + { + "x": 97.296875, + "y": 446.5, + "width": 44.453125, + "height": 44.453125, + "textAlign": "center" + }, + { + "x": 147.59375, + "y": 446.5, + "width": 44.46875, + "height": 44.46875, + "textAlign": "center" + }, + { + "x": 197.90625, + "y": 446.5, + "width": 44.46875, + "height": 44.46875, + "textAlign": "center" + }, + { + "x": 248.21875, + "y": 446.5, + "width": 44.46875, + "height": 44.46875, + "textAlign": "center" + }, + { + "x": 298.53125, + "y": 446.5, + "width": 44.46875, + "height": 44.46875, + "textAlign": "center" + } + ], + "media": "not all", + "overflow": false + }, + "1440": { + "boxes": [ + { + "x": 522, + "y": 440.234375, + "width": 56, + "height": 56, + "textAlign": "center" + }, + { + "x": 590, + "y": 440.234375, + "width": 56, + "height": 56, + "textAlign": "center" + }, + { + "x": 658, + "y": 440.234375, + "width": 56, + "height": 56, + "textAlign": "center" + }, + { + "x": 726, + "y": 440.234375, + "width": 56, + "height": 56, + "textAlign": "center" + }, + { + "x": 794, + "y": 440.234375, + "width": 56, + "height": 56, + "textAlign": "center" + }, + { + "x": 862, + "y": 440.234375, + "width": 56, + "height": 56, + "textAlign": "center" + } + ], + "media": "not all", + "overflow": false + } +} \ No newline at end of file diff --git a/Docs/Testing/TwoFactorOtp-20261125/before-1440.png b/Docs/Testing/TwoFactorOtp-20261125/before-1440.png new file mode 100644 index 00000000..a2d06bdb Binary files /dev/null and b/Docs/Testing/TwoFactorOtp-20261125/before-1440.png differ diff --git a/Docs/Testing/TwoFactorOtp-20261125/before-320.png b/Docs/Testing/TwoFactorOtp-20261125/before-320.png new file mode 100644 index 00000000..6235f23b Binary files /dev/null and b/Docs/Testing/TwoFactorOtp-20261125/before-320.png differ diff --git a/Docs/Testing/TwoFactorOtp-20261125/before-390.png b/Docs/Testing/TwoFactorOtp-20261125/before-390.png new file mode 100644 index 00000000..72cbb6cd Binary files /dev/null and b/Docs/Testing/TwoFactorOtp-20261125/before-390.png differ diff --git a/Docs/Testing/TwoFactorOtp-20261125/before-geometry.json b/Docs/Testing/TwoFactorOtp-20261125/before-geometry.json new file mode 100644 index 00000000..f4297384 --- /dev/null +++ b/Docs/Testing/TwoFactorOtp-20261125/before-geometry.json @@ -0,0 +1,146 @@ +{ + "320": { + "boxes": [ + { + "x": 47, + "y": 435.25, + "width": 226, + "height": 35.75, + "textAlign": "start" + }, + { + "x": 47, + "y": 471, + "width": 226, + "height": 35.75, + "textAlign": "start" + }, + { + "x": 47, + "y": 506.75, + "width": 226, + "height": 35.75, + "textAlign": "start" + }, + { + "x": 47, + "y": 542.5, + "width": 226, + "height": 35.75, + "textAlign": "start" + }, + { + "x": 47, + "y": 578.25, + "width": 226, + "height": 35.75, + "textAlign": "start" + }, + { + "x": 47, + "y": 614, + "width": 226, + "height": 35.75, + "textAlign": "start" + } + ], + "media": "not all", + "overflow": false + }, + "390": { + "boxes": [ + { + "x": 47, + "y": 435.25, + "width": 296, + "height": 35.75, + "textAlign": "start" + }, + { + "x": 47, + "y": 471, + "width": 296, + "height": 35.75, + "textAlign": "start" + }, + { + "x": 47, + "y": 506.75, + "width": 296, + "height": 35.75, + "textAlign": "start" + }, + { + "x": 47, + "y": 542.5, + "width": 296, + "height": 35.75, + "textAlign": "start" + }, + { + "x": 47, + "y": 578.25, + "width": 296, + "height": 35.75, + "textAlign": "start" + }, + { + "x": 47, + "y": 614, + "width": 296, + "height": 35.75, + "textAlign": "start" + } + ], + "media": "not all", + "overflow": false + }, + "1440": { + "boxes": [ + { + "x": 429, + "y": 428.234375, + "width": 582, + "height": 38, + "textAlign": "start" + }, + { + "x": 429, + "y": 466.234375, + "width": 582, + "height": 38, + "textAlign": "start" + }, + { + "x": 429, + "y": 504.234375, + "width": 582, + "height": 38, + "textAlign": "start" + }, + { + "x": 429, + "y": 542.234375, + "width": 582, + "height": 38, + "textAlign": "start" + }, + { + "x": 429, + "y": 580.234375, + "width": 582, + "height": 38, + "textAlign": "start" + }, + { + "x": 429, + "y": 618.234375, + "width": 582, + "height": 38, + "textAlign": "start" + } + ], + "media": "not all", + "overflow": false + } +} \ No newline at end of file diff --git a/PlotLine.Tests/Browser/two-factor-otp.cjs b/PlotLine.Tests/Browser/two-factor-otp.cjs new file mode 100644 index 00000000..d41df9d2 --- /dev/null +++ b/PlotLine.Tests/Browser/two-factor-otp.cjs @@ -0,0 +1,47 @@ +// Run against a loopback visual host rendering the real Account/TwoFactor view +// with a synthetic pending challenge. No real user, TOTP or database is needed. +const {chromium}=require('playwright'); +const assert=require('node:assert/strict'); +const fs=require('node:fs'); +const base=process.env.OTP_VISUAL_URL||'http://127.0.0.1:5282'; +const output=process.env.OTP_SCREENSHOTS; +if(!/^http:\/\/127\.0\.0\.1:\d+$/.test(base))throw Error('Loopback visual fixture required'); +(async()=>{const browser=await chromium.launch();try{ + for(const width of [1440,390,320]){ + const page=await browser.newPage({viewport:{width,height:950}}); + await page.goto(base+'/Account/TwoFactor'); + const digits=page.locator('[data-two-factor-digit]');assert.equal(await digits.count(),6); + const geometry=await digits.evaluateAll(xs=>xs.map(x=>{const r=x.getBoundingClientRect();return{x:r.x,y:r.y,w:r.width,h:r.height,align:getComputedStyle(x).textAlign}})); + assert(geometry.every(x=>Math.abs(x.y-geometry[0].y)<.1&&Math.abs(x.w-geometry[0].w)<.1&&Math.abs(x.w-x.h)<.1&&x.align==='center')); + assert(geometry[0].w<=56&&geometry[0].w>=24); + const gaps=geometry.slice(1).map((x,i)=>x.x-geometry[i].x-geometry[i].w);assert(gaps.every(x=>x>0&&Math.abs(x-gaps[0])<.1)); + assert.equal(await page.evaluate(()=>document.documentElement.scrollWidth>innerWidth),false); + const action=await page.locator('.two-factor-actions').boundingBox();assert(action.y-geometry[0].y-geometry[0].h>=20); + for(let i=0;i<6;i++){ + assert.equal(await digits.nth(i).getAttribute('aria-label'),`Digit ${i+1} of 6`); + assert.equal(await digits.nth(i).getAttribute('inputmode'),'numeric');assert.equal(await digits.nth(i).getAttribute('maxlength'),'1'); + assert.equal(await digits.nth(i).getAttribute('autocomplete'),'one-time-code');assert.equal(await digits.nth(i).getAttribute('pattern'),'[0-9]*'); + } + const focus=await digits.first().evaluate(x=>{const s=getComputedStyle(x);return s.outlineStyle!=='none'||s.boxShadow!=='none'});assert(focus); + await page.evaluate(()=>{window.otpSubmissions=[];document.querySelector('form[data-two-factor-form]').addEventListener('submit',e=>{e.preventDefault();window.otpSubmissions.push(document.querySelector('[data-two-factor-code]').value)});}); + await digits.first().press('a');assert.equal(await digits.first().inputValue(),'');assert(await digits.first().evaluate(x=>x===document.activeElement)); + for(let i=0;i<6;i++){await digits.nth(i).press(String(i+1));if(i<5)assert(await digits.nth(i+1).evaluate(x=>x===document.activeElement));} + assert.equal(await page.locator('[data-two-factor-code]').inputValue(),'123456');assert.deepEqual(await page.evaluate(()=>window.otpSubmissions),['123456']); + if(output)await page.screenshot({path:`${output}/after-${width}.png`,fullPage:true}); + assert.equal(await page.locator('form[data-two-factor-form]').getAttribute('method'),'post');assert.equal(await page.locator('input[name=__RequestVerificationToken]').count(),1); + await page.reload();await page.evaluate(()=>{window.otpSubmissions=[];document.querySelector('[data-two-factor-form]').addEventListener('submit',e=>{e.preventDefault();window.otpSubmissions.push(document.querySelector('[data-two-factor-code]').value)});}); + await digits.first().evaluate(x=>{const d=new DataTransfer();d.setData('text','12 34-56');x.dispatchEvent(new ClipboardEvent('paste',{bubbles:true,cancelable:true,clipboardData:d}));}); + assert.deepEqual(await digits.evaluateAll(xs=>xs.map(x=>x.value)),['1','2','3','4','5','6']);assert.deepEqual(await page.evaluate(()=>window.otpSubmissions),['123456']); + await page.reload();await digits.first().press('1');await digits.nth(1).press('2');await digits.nth(2).press('Backspace'); + assert(await digits.nth(1).evaluate(x=>x===document.activeElement));assert.deepEqual((await digits.evaluateAll(xs=>xs.map(x=>x.value))).slice(0,3),['1','','']); + await digits.nth(1).press('Tab');assert(await digits.nth(2).evaluate(x=>x===document.activeElement));await digits.nth(2).press('Shift+Tab');assert(await digits.nth(1).evaluate(x=>x===document.activeElement)); + await digits.nth(1).press('ArrowLeft');await digits.nth(1).press('ArrowRight');assert.deepEqual((await digits.evaluateAll(xs=>xs.map(x=>x.value))).slice(0,3),['1','','']); + assert.equal(await page.getByRole('link',{name:'Use a recovery code.'}).getAttribute('href'),'/Account/TwoFactorRecovery?returnUrl=%2F'); + // Empty Code uses the existing server-side required validation, never TOTP. + await page.reload();const response=page.waitForResponse(r=>r.url().endsWith('/Account/TwoFactor')&&r.request().method()==='POST'); + await page.getByRole('button',{name:'Continue',exact:true}).click();assert.equal((await response).status(),200);await page.waitForLoadState(); + assert(await page.getByText('Enter the code from your authenticator app.',{exact:true}).isVisible());assert.equal(await page.locator('[data-two-factor-digit]').count(),6); + await page.close(); + } + console.log('PASS Chromium OTP: desktop/390/320 single row, equal squares/gaps, centred text, focus, no overflow, spacing, numeric input, advancement, paste, backspace, tab/arrows, accessibility, auto-POST payload/antiforgery and real required validation.'); +}finally{await browser.close();}})().catch(e=>{console.error(e);process.exit(1)}); diff --git a/PlotLine/wwwroot/css/public-site.css b/PlotLine/wwwroot/css/public-site.css index 71fb522d..f49f44d0 100644 --- a/PlotLine/wwwroot/css/public-site.css +++ b/PlotLine/wwwroot/css/public-site.css @@ -229,6 +229,25 @@ html[data-site-theme="public"] { .auth-field-stack { display: grid; gap: 20px; } .auth-actions { margin-top: 24px; } .auth-help { margin-top: 20px; font-size: 13px; } + /* OTP geometry must not depend on the installed-window-only legacy theme. */ + .two-factor-code-group { margin-bottom: 1.5rem; } + .two-factor-inputs { + display: grid; + grid-template-columns: repeat(6, minmax(0, 3.5rem)); + justify-content: center; + gap: clamp(.25rem, 1.5vw, .75rem); + width: 100%; + margin-top: .75rem; + } + .two-factor-inputs > .two-factor-digit { + width: 100%; + min-width: 0; + height: auto; + aspect-ratio: 1; + padding: 0; + text-align: center; + font-size: clamp(1.1rem, 4vw, 1.6rem); + } .form-check { display: flex; align-items: center; gap: 8px; } .form-check-input { float: none; margin-top: 0; } .public-auth-main .trial-status-panel { padding: 24px; margin-bottom: 28px; background: var(--sage); border: 1px solid #d4dbc6; border-radius: 5px; }