↩ Back to CV

Technical case study

TOTP-based 2FA for patient data protection in healthcare software

TOTP-based 2FA protecting patient data in a CakePHP healthcare application with role-based access, trusted devices, migrations, and security testing.

Context

The project concerned a cloud medical web application that handles patient data. In the context of Germany's Digital-Gesetz (DigiG), the project ticket called for two-factor authentication to strengthen access protection for cloud systems that handle this data.

The implementation had to fit the application's existing authentication flow, roles, and access rights. It also needed practical user and administrator workflows across different browsers and terminals rather than a standalone code-checking screen.

Standards and provisioning

I implemented TOTP as specified in RFC 6238, which builds on HOTP as defined by RFC 4226. The solution works with Google Authenticator and compatible authenticator applications.

The setup flow generates and manages a TOTP secret for each user, provides QR-based provisioning, and validates one-time codes before 2FA is activated for the account.

Authentication and session security

I integrated 2FA into the existing CakePHP application through Middleware, Controllers, Helpers, and ORM-backed state. The implementation handles cookies, session state, login and logout behavior, and security-sensitive transitions explicitly.

Trusted sessions are kept separately for each browser or terminal. A successful second factor can establish trust for 24 hours, while an administrator can revoke that state and force the user through 2FA again.

Authorization, migrations, and testing

Role and access-right checks govern user and administrative actions for enabling, disabling, and enforcing 2FA. Database migrations introduced the required security fields and permissions while accounting for compatibility issues in the existing system.

PHPUnit tests cover authentication middleware, controllers, and negative scenarios. Functional testing checks different roles, browsers, and terminals; the responsive setup interface also accounts for accessibility requirements around images and QR codes.

Technologies and concepts

  • PHP
  • CakePHP
  • 2FA
  • TOTP
  • HOTP
  • RFC 6238
  • RFC 4226
  • Google Authenticator
  • Authentication middleware
  • Session security
  • Trusted devices
  • RBAC
  • Database migrations
  • PHPUnit
  • Security testing
  • Responsive UI
  • Accessibility