OTP simplificada con one-time-pass

Biblioteca ligera one-time-pass para generar TOTP y HOTP compatibles con RFC 6238/4226. Sin dependencias, API simple para Node.js y navegador, ideal para 2FA.

31 ago 2025 • 2 min read • Q2BSTUDIO Team

Inteligencia-Artificial-

Las contraseñas de un solo uso OTP son un pilar de la autenticación moderna y añaden una capa extra de seguridad mediante 2FA.

Que es one-time-pass

one-time-pass es una biblioteca ligera y potente que genera códigos TOTP basados en tiempo y HOTP basados en contador. Cumple con los estándares RFC 6238 y RFC 4226, por lo que los códigos son compatibles con aplicaciones populares como Google Authenticator. Su mayor virtud es la simplicidad: con cero dependencias reduce al mínimo la huella de tu proyecto y evita conflictos, ideal para integrarlo en aplicaciones a cualquier escala.

Primeros pasos: instalación y uso

Para comenzar, instálalo con npm i one-time-pass. La biblioteca ofrece una sintaxis moderna compatible con ES modules y una API directa para integrarlo rápidamente en tu backend o frontend.

Generación de TOTP

Los TOTP se calculan con el tiempo actual y una clave secreta compartida. Puedes ajustar parámetros como timeStep en segundos con valor por defecto 30, digits con valor por defecto 6 y el algoritmo de hash como sha1, sha256 o sha512. La clave secreta debe ser única por usuario y almacenarse de forma segura.

Generación de HOTP

Los HOTP se basan en un contador que avanza con cada uso. Son útiles cuando no hay una fuente de tiempo fiable. Proporciona la clave secreta, el valor del contador y configura digits y hash del mismo modo que en TOTP.

Uso en navegador

Si desarrollas en el lado del cliente, puedes cargar la librería desde un CDN como jsdelivr y utilizar sus funciones disponibles en un objeto global, sin necesidad de herramientas adicionales.

Buenas prácticas de seguridad

Genera secretos únicos por usuario, aplica rotación y almacenamiento seguro, sincroniza relojes en servidores para TOTP y contempla una pequeña ventana de validación para tolerar ligeras desincronizaciones. En entornos de alta seguridad combina OTP con restricciones de IP, listas de dispositivos confiables y monitoreo de intentos.

Conclusión

Tanto en Node.js como en aplicaciones web, one-time-pass ofrece una forma sencilla, fiable y eficiente de generar OTP. Su enfoque sin dependencias y la adhesión a estándares abiertos lo convierten en una opción excelente para implementar 2FA de manera robusta y sin sobrecarga.

En Q2BSTUDIO te ayudamos a llevar esta seguridad a tus productos. Somos una empresa de desarrollo de software y aplicaciones a medida, especialistas en inteligencia artificial, ciberseguridad, servicios cloud aws y azure, servicios inteligencia de negocio, agentes IA, ia para empresas, power bi y automatización de procesos. Si necesitas reforzar la protección de tus sistemas con auditorías y pruebas de intrusión, visita nuestros servicios de ciberseguridad y pentesting. Y si buscas integrar OTP en plataformas nuevas o existentes, consultanos sobre software a medida y desarrollo multiplataforma para una implementación alineada con tus objetivos.

Para saber más o contribuir al proyecto, visita el repositorio oficial one-time-pass en GitHub.

A BREAK?

Play for a moment before you go

OUR SERVICES

How we can help you

Artificial intelligence

AI agents, chatbots, and intelligent assistants that automate tasks and serve your customers 24/7 to improve the efficiency of your business.

More info

Software Development

Web, mobile, and desktop applications, intranets, e-commerce, SaaS, and management platforms designed for your company's specific needs.

More info

Cloud services

Migration, infrastructure, managed hosting, high availability, and security on Microsoft Azure and Amazon Web Services to help your business scale without limits.

More info

Cybersecurity and pentesting

Security audits, penetration testing and protection of applications, data and infrastructure on-premise and cloud, with ethical hacking and regulatory compliance.

More info

Business Intelligence

Dashboards and data analysis with Power BI: we integrate your sources, design dashboards and KPIs and turn your data into decisions.

More info

Process automation

We automate repetitive tasks and connect your applications with n8n, Power Automate, Make, and RPA, eliminating manual work and increasing productivity.

More info

Training for Companies

We train your teams in technology with criteria: web development, databases, Git, best practices and security, automation with n8n, artificial intelligence for companies and creation of AI solutions with Azure AI Foundry.

More info

Code Auditing

We audit the code that you, your team or an AI create: we tell you what is good and what to improve, we secure it and make it ready for production, web or app.

More info

AI Image Generation

We create for you the images that your business needs with artificial intelligence: product, networks, advertising, illustration and avatars. You tell us what you want and we deliver it ready to use.

More info

AI Video Generation

We create videos with artificial intelligence for you: promotional, networking, virtual presenters, dubbing and animations. You tell us the idea and we will deliver it assembled and ready to publish.

More info

AI Conversational Avatars

We create conversational avatars with AI – digital humans with a face and voice – that serve your customers and teams with the knowledge of your company, on your website, interactive monitors, WhatsApp or Teams.

More info

Online Marketing and AI

Google Ads, Meta Ads, LinkedIn Ads and AI Engine Positioning (GEO/AEO): we attract customers and make your brand appear where they search for you, also on ChatGPT, Gemini and Perplexity.

More info

Do you have a project in mind?

Tell us your vision and we'll turn it into a software solution. Whatever the scope, we make your idea real.

Live Chat