不要放手机号了,还是用用户名吧。看一下用用户名能不能登录?能用就直接放用户名。
Auth::attempt() 只按 phone_hash 查:
Auth::attempt()
phone_hash
$phoneHash = hash('sha256', $phone); 'SELECT * FROM users WHERE phone_hash = ? AND role IN ("admin","user") AND status = "active" LIMIT 1'
线上实测:
laoyang
12345678
13361281915
⇒ 用户名登录不支持。想让登录页展示用户名,必须先改代码。
用户先前要求「这个改动不要提交到代码库」。但支持用户名登录属于功能改动, 必须改 src/Auth.php + AuthController + 模板,无法只存在于线上。 已与用户确认,选择走正规流程入仓库。
src/Auth.php
AuthController
name
family_id
role in (admin,user)
status=active
attempt()
return null
src/Controllers/AuthController.php
templates/auth/login.php
逻辑单测 10/10(Auth::attempt 直调,不经 HTTP):
Auth::attempt
反向验证:把 count($rows) !== 1 改成 count($rows) < 1(= 取第一条), 断言立刻变红并报出「误登进 id=1」;恢复后回绿。
count($rows) !== 1
count($rows) < 1
端到端(线上 HTTP):
d6a7cc9
fdc890f..d6a7cc9
登录页的「演示站点」提示块只在线上、不入库(用户明确要求)。 ⇒ 下次部署 templates/auth/login.php 会把它冲掉,需要重打。 建议后续做成部署后置钩子,但属于另一件事。
No dependencies set.
The note is not visible to the blocked user.
需求
现状(已实测,不是推断)
Auth::attempt()只按phone_hash查:线上实测:
laoyang+1234567813361281915+12345678⇒ 用户名登录不支持。想让登录页展示用户名,必须先改代码。
与「不改代码」的冲突(已向用户确认)
用户先前要求「这个改动不要提交到代码库」。但支持用户名登录属于功能改动,
必须改
src/Auth.php+AuthController+ 模板,无法只存在于线上。已与用户确认,选择走正规流程入仓库。
改法
Auth::attempt():先按phone_hash查;查不到再按name查(
family_id范围内、role in (admin,user)、status=active)。验收
laoyang/12345678能登录 → 20013361281915/12345678仍能登录 → 200(不能破坏原路径)验收记录
改了什么
src/Auth.phpattempt()先按phone_hash精确查,未命中再按name查;重名命中多条一律return nullsrc/Controllers/AuthController.phptemplates/auth/login.php怎么验的
逻辑单测 10/10(
Auth::attempt直调,不经 HTTP):13361281915+ 正确密码 → 登录成功,name=laoyanglaoyang+ 正确密码 → 登录成功,id=1(与手机号同一账号)反向验证:把
count($rows) !== 1改成count($rows) < 1(= 取第一条),断言立刻变红并报出「误登进 id=1」;恢复后回绿。
端到端(线上 HTTP):
部署
d6a7cc9,已推送fdc890f..d6a7cc9遗留
登录页的「演示站点」提示块只在线上、不入库(用户明确要求)。
⇒ 下次部署
templates/auth/login.php会把它冲掉,需要重打。建议后续做成部署后置钩子,但属于另一件事。