[{"data":1,"prerenderedAt":407},["ShallowReactive",2],{"blog:en:how-a-login-works":3,"blog-next:en":329},{"id":4,"title":5,"author":6,"body":7,"date":313,"description":314,"extension":315,"meta":316,"navigation":318,"path":319,"publishAt":320,"seo":321,"stem":322,"tags":323,"__hash__":328},"blog_en\u002Fblog\u002Fhow-a-login-works\u002Fen.md","How a login works","Aptli",{"type":8,"value":9,"toc":296},"minimark",[10,14,17,20,23,28,40,50,60,67,74,81,88,95,102,109,116,122,126,131,134,138,141,145,148,152,155,159,162,166,169,173,176,180,183,277,280,283,286,289,293],[11,12,13],"p",{},"Our co-op student's first project was a website of her own that no customer depends on. It teaches our file structure, our naming conventions and the patterns we use to bundle components and utilities. It also gives her a base to build on.",[11,15,16],{},"The pages and routing came together quickly. Login was the first hard problem. It is complex for anyone who hasn't built one before, and a diagram helps. This is how we approached it.",[11,18,19],{},"Login looks like one form. Behind it, the browser, the server and the database pass a dozen messages, and checks along the way keep an account safe.",[11,21,22],{},"This is the basic pattern for login, and every developer on our team learns it first.",[24,25,27],"h2",{"id":26},"the-backbone","The backbone",[11,29,30,31,39],{},"  ",[32,33,35],"span",{"style":34},"color:#2563eb",[36,37,38],"strong",{},"Browser:"," sends the login details to the server.",[11,41,42,43,49],{},"      ",[32,44,46],{"style":45},"color:#0f766e",[36,47,48],{},"Server:"," looks up the user.",[11,51,52,53,59],{},"          ",[32,54,56],{"style":55},"color:#7c3aed",[36,57,58],{},"Database:"," returns the stored record.",[11,61,42,62,66],{},[32,63,64],{"style":45},[36,65,48],{}," verifies the login details against the stored record and creates a session with an expiry.",[11,68,52,69,73],{},[32,70,71],{"style":55},[36,72,58],{}," stores the session.",[11,75,42,76,80],{},[32,77,78],{"style":45},[36,79,48],{}," returns a token to the browser in a cookie.",[11,82,30,83,87],{},[32,84,85],{"style":34},[36,86,38],{}," sends that cookie with every request that follows.",[11,89,42,90,94],{},[32,91,92],{"style":45},[36,93,48],{}," checks the session before it returns any data.",[11,96,52,97,101],{},[32,98,99],{"style":55},[36,100,58],{}," confirms the session exists and is still live.",[11,103,42,104,108],{},[32,105,106],{"style":45},[36,107,48],{}," rejects an expired session and ends the session when the user logs out.",[11,110,52,111,115],{},[32,112,113],{"style":55},[36,114,58],{}," deletes the session record either way.",[11,117,118],{},[119,120],"img",{"alt":5,"src":121},"\u002Fimages\u002Fblog\u002Fhow-a-login-works\u002Flogin-flow.png",[24,123,125],{"id":124},"key-checkpoints","Key checkpoints",[127,128,130],"h3",{"id":129},"the-server-decides-on-every-request","The server decides on every request",[11,132,133],{},"The server decides who the user is and what they can reach. The browser presents the login details or the token. The server validates them, checks the session record in the database on every request and replies with what that user may see. A request without a live session gets a 401 and no data.",[127,135,137],{"id":136},"store-a-slow-hash-of-each-password","Store a slow hash of each password",[11,139,140],{},"The server stores a slow, one-way hash of each password with a unique salt. The password itself is never stored. At login the server hashes the submitted password the same way and compares the two results. A stolen database holds only salted hashes, and every guess against them is slow.",[127,142,144],{"id":143},"keep-the-token-in-a-protected-cookie","Keep the token in a protected cookie",[11,146,147],{},"The browser attaches a cookie to every request to your site automatically, and it can keep the cookie out of reach of scripts on the page. Set three flags on the cookie. HttpOnly keeps scripts on the page from reading it. Secure sends it only over HTTPS. SameSite keeps other sites from attaching it to the forms and background requests they send to yours.",[127,149,151],{"id":150},"check-access-on-every-data-request","Check access on every data request",[11,153,154],{},"A live session proves who the user is. Each call that returns data also checks that this user may see the record requested. Each customer's session reaches only that customer's data.",[127,156,158],{"id":157},"give-every-session-an-expiry","Give every session an expiry",[11,160,161],{},"The server stores each session in the database with its expiry. On every request the server checks that expiry before it returns data. A session ends at a set time or after a period of inactivity, and the server deletes its record from the database. A short expiry and an inactivity timeout limit how long a copied token works.",[127,163,165],{"id":164},"log-out-on-the-server","Log out on the server",[11,167,168],{},"The browser asks the server to log out. The server deletes the session record from the database and then clears the cookie. A copied token stops working the moment the record is gone.",[127,170,172],{"id":171},"answer-every-failed-login-the-same-way","Answer every failed login the same way",[11,174,175],{},"\"Incorrect username or password\" covers every failure. Separate messages for an unknown user and a wrong password tell an attacker which accounts exist. The server also slows repeated attempts for each account and each address.",[24,177,179],{"id":178},"the-code-by-workflow","The code, by workflow",[11,181,182],{},"The diagram shows a dozen messages. The code behind them follows the workflow. One call handles several steps, and the logic the steps share lives in one place.",[184,185,186,202],"table",{},[187,188,189],"thead",{},[190,191,192,196,199],"tr",{},[193,194,195],"th",{},"Workflow",[193,197,198],{},"Example",[193,200,201],{},"Covers",[203,204,205,220,231,242,255,266],"tbody",{},[190,206,207,211,217],{},[208,209,210],"td",{},"Log in",[208,212,213],{},[214,215,216],"code",{},"POST \u002Fapi\u002Flogin",[208,218,219],{},"Hashing, the protected cookie and the single failure message",[190,221,222,225,228],{},[208,223,224],{},"Every request",[208,226,227],{},"A check that runs before each protected route",[208,229,230],{},"The server's decision, the live session and expiry",[190,232,233,236,239],{},[208,234,235],{},"Data calls",[208,237,238],{},"Each endpoint that returns records",[208,240,241],{},"Data access for the record requested",[190,243,244,247,252],{},[208,245,246],{},"Log out",[208,248,249],{},[214,250,251],{},"POST \u002Fapi\u002Flogout",[208,253,254],{},"Ending the session on the server and in the database",[190,256,257,260,263],{},[208,258,259],{},"Shared logic",[208,261,262],{},"One module the calls above share",[208,264,265],{},"Password hashing, sessions, cookie flags and expiry",[190,267,268,271,274],{},[208,269,270],{},"Browser side",[208,272,273],{},"One helper every page uses",[208,275,276],{},"Login, logout and the current user",[11,278,279],{},"The login call runs the whole login in one request. It looks up the user, compares the hashes and sets the cookie. It returns the same error for every failure.",[11,281,282],{},"The request check runs before every protected route. It reads the cookie, checks the session in the database and answers 401 when the session is gone.",[11,284,285],{},"The shared module holds the logic the calls above share. Hashing, the cookie flags and the expiry rule each live there once. Every call applies them the same way.",[11,287,288],{},"The browser helper gives every page the same login, logout and current user. It shapes what the page shows. The server decides what data leaves.",[24,290,292],{"id":291},"building-on-it","Building on it",[11,294,295],{},"The pattern is extensible, and that is its main benefit. Once the fundamentals are in place, each piece becomes something you can switch out. Single sign-on through OpenID Connect or SAML changes how a user proves who they are. So do passkeys. Middleware on the server and in the browser hooks into the same steps. Every one of them starts from the basics above.",{"title":297,"searchDepth":298,"depth":298,"links":299},"",2,[300,301,311,312],{"id":26,"depth":298,"text":27},{"id":124,"depth":298,"text":125,"children":302},[303,305,306,307,308,309,310],{"id":129,"depth":304,"text":130},3,{"id":136,"depth":304,"text":137},{"id":143,"depth":304,"text":144},{"id":150,"depth":304,"text":151},{"id":157,"depth":304,"text":158},{"id":164,"depth":304,"text":165},{"id":171,"depth":304,"text":172},{"id":178,"depth":298,"text":179},{"id":291,"depth":298,"text":292},"2026-11-16","Login looks like one form. Behind it, the browser, the server and the database pass a dozen messages, and checks along the way keep an account safe. This is the basic pattern every developer on our team learns first.","md",{"announceUntil":317},"2026-11-24",true,"\u002Fblog\u002Fhow-a-login-works\u002Fen","2026-11-16T00:00:00Z",{"title":5,"description":314},"blog\u002Fhow-a-login-works\u002Fen",[324,325,326,327],"engineering","how-we-work","authentication","security","XDLegGzeW45UOgtqek4Ez1I8dXhMGsVCyIJf7SUXIrg",[330,334,338,342,346,350,354,358,362,366,367,371,375,379,383,387,391,395,399,403],{"title":331,"description":332,"path":333},"A government put a date on AI adoption","On June 4, 2026, Canada launched a national AI strategy built around an adoption target with a year attached to it. That specificity is the part worth looking at closely.","\u002Fblog\u002Fa-date-on-ai-adoption\u002Fen",{"title":335,"description":336,"path":337},"A milestone day at Aptli","This morning, Ontario Centre of Innovation approved Aptli for CIT Development and Commercialization funding. A few hours later, we signed our first commercial trial. What this moment means, and what comes next.","\u002Fblog\u002Fa-milestone-day\u002Fen",{"title":339,"description":340,"path":341},"As-built records that grow with the work","An as-built record is most accurate when it is written as the work happens. Here is how the map becomes the as-built, one reviewed field change at a time.","\u002Fblog\u002Fas-built-records\u002Fen",{"title":343,"description":344,"path":345},"The broadband buildout has a back-office problem","Billions in government funding are flowing into fibre deployment, and the policy is in place. Executing it depends on the back office that coordinates the construction, and that is where capacity decides the pace.","\u002Fblog\u002Fbroadband-back-office-problem\u002Fen",{"title":347,"description":348,"path":349},"Contractor separation in two layers","When several parties share a platform (staff, subcontractors, even competing contractors), each one needs to see its own work and the shared layers. Here is how two layers of authorization give them that.","\u002Fblog\u002Fcontractor-separation\u002Fen",{"title":351,"description":352,"path":353},"Data sovereignty: the new geopolitical battleground","Control over data has become inseparable from national security, economic competitiveness, and democratic resilience. Here is where the problem came from, why it matters now, and what organizations can do about it.","\u002Fblog\u002Fdata-sovereignty\u002Fen",{"title":355,"description":356,"path":357},"Fall 2026 changelog: one tree for the work, enforcement cases and a portal that listens","What shipped since midsummer: projects and work in one tree, assets and inventory on one page, investigations and charges with their documents, sensor readings driving automations, Power BI reporting and a service portal that picks the form from a spoken description.","\u002Fblog\u002Ffall-2026-changelog\u002Fen",{"title":359,"description":360,"path":361},"Git for field data","Software development settled concurrent editing long ago with staging, committing, conflict checks and code review. Field data has the same needs, and Aptli applies the same model.","\u002Fblog\u002Fgit-for-field-data\u002Fen",{"title":363,"description":364,"path":365},"Govern AI by what you build","Privacy practice works by blocking because an organization owns the places its data lives. AI use happens in a text box it does not own. The control that works there is a better path that keeps a record.","\u002Fblog\u002Fgovern-ai-by-what-you-build\u002Fen",{"title":5,"description":314,"path":319},{"title":368,"description":369,"path":370},"How we agree on a shape before we build it","A few weeks ago we wrote about how design patterns show up in our code without classes. The conversation inside our own team did not stop when we hit publish. This is the habit underneath all of it, and why we treat it as deliberate work.","\u002Fblog\u002Fhow-we-agree-on-a-shape\u002Fen",{"title":372,"description":373,"path":374},"Where did the cable go? Material chain of custody from warehouse to installation","Most material shrinkage in field operations is accounting: the gap between what was issued and what can be accounted for. Here is how a recorded chain of custody closes it, from warehouse to installation.","\u002Fblog\u002Fmaterial-chain-of-custody\u002Fen",{"title":376,"description":377,"path":378},"The question a Java developer asked us","Which design patterns do you use? Our front end has almost no classes in it. The answer turned into a good description of how we decide what to build and how we talk to each other about it.","\u002Fblog\u002Fobject-oriented-without-classes\u002Fen",{"title":380,"description":381,"path":382},"A permit tracked beside the work it clears","A permit gates the work, and it belongs beside the work. Here is how Aptli carries a permit as a work order, with the same planning, tracking, validation and audit trail as the job it clears.","\u002Fblog\u002Fpermitting-without-a-module\u002Fen",{"title":384,"description":385,"path":386},"PHP2Shell and Aptli","Aptli has checked its systems against PHP2Shell, the PHP remote code execution flaws disclosed on October 20. Aptli is not affected.","\u002Fblog\u002Fphp2shell\u002Fen",{"title":388,"description":389,"path":390},"Where fiber build delays start, and how to catch them early","A late broadband project gets explained by permits, utilities and supply chains. Tracing a delay back to where it started often leads to coordination inside the project, and that part can be fixed.","\u002Fblog\u002Freal-reason-fiber-is-late\u002Fen",{"title":392,"description":393,"path":394},"When the rules move faster than your release cycle","AI and privacy law changes faster than most product cycles. The lasting question is whether you can absorb the next change, or whether you leave that market. Here is how we think about that decision.","\u002Fblog\u002Frules-move-faster-than-release-cycle\u002Fen",{"title":396,"description":397,"path":398},"The role under the name","A Java developer once asked which design patterns we use. The conversation since has settled on a simpler point. A pattern name is a shortcut, and the role under it is what a team shares.","\u002Fblog\u002Fthe-role-under-the-name\u002Fen",{"title":400,"description":401,"path":402},"We funded the network. Now let's build it.","Canada has committed record funding to broadband infrastructure. Turning that funding into networks is now an execution problem, and here is what it takes to close the gap.","\u002Fblog\u002Fwe-funded-the-network\u002Fen",{"title":404,"description":405,"path":406},"Where broadband projects lose money, and how to close the leaks","A network going live settles whether a build hit its budget. Finding where the money leaked takes more work. Here are seven places projects lose money, and what closes each one.","\u002Fblog\u002Fwhere-broadband-projects-lose-money\u002Fen",1794858595014]