# compare-timing-safe

> String comparison in length constant time

Latest version **2.1.2** (published 2024-10-23) · Unlicense license · 0 weekly downloads

## Install

```sh
npm install compare-timing-safe
pnpm add compare-timing-safe
yarn add compare-timing-safe
bun add compare-timing-safe
```

## Health

**Score 30/100 (F)** — status: maintenance-mode.

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types.

Negative: stale; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.1.2 |
| Published | 2024-10-23 |
| First published | 2017-07-16 |
| Weekly downloads | 0 |
| License | Unlicense |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 6.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | commenthol |
| Maintainers | commenthol |
| Keywords | compare, constant, equal, length, safe, string, time, timing |

## Links

- npm: https://www.npmjs.com/package/compare-timing-safe
- Repository: https://github.com/commenthol/compare-timing-safe
- Homepage: https://github.com/commenthol/compare-timing-safe#readme
- Issues: https://github.com/commenthol/compare-timing-safe/issues
- npm.io page: https://npm.io/package/compare-timing-safe

## Alternatives

- [@js-joda/timezone](https://npm.io/package/@js-joda/timezone.md) — 383.4K weekly downloads
- [chartjs-adapter-moment](https://npm.io/package/chartjs-adapter-moment.md) — 210.8K weekly downloads
- [strftime](https://npm.io/package/strftime.md) — 171.2K weekly downloads
- [vue-flatpickr-component](https://npm.io/package/vue-flatpickr-component.md) — 115.8K weekly downloads
- [timepicker](https://npm.io/package/timepicker.md) — 51.0K weekly downloads

## Recent versions

- 2.1.2 (latest) — 2024-10-23
- 2.1.1 — 2022-11-12
- 2.1.0 — 2022-06-25
- 2.0.2 — 2022-04-15
- 2.0.1 — 2022-03-26
- 2.0.0 — 2022-03-26
- 1.0.0 — 2017-07-16

## README

[![NPM version](https://badge.fury.io/js/compare-timing-safe.svg)](https://www.npmjs.com/package/compare-timing-safe/)
[![Build Status](https://github.com/commenthol/compare-timing-safe/workflows/CI/badge.svg?branch=master&event=push)](https://github.com/commenthol/compare-timing-safe/actions/workflows/ci.yml?query=branch%3Amaster)

# compare-timing-safe

> String comparison in length constant time

Works in node and in the browser.

Node version uses `crypto` module.

### `timingSafeEqual(a, b)`

String, buffer comparison in length-constant time

**Example**

```js
import timingSafeEqual from 'compare-timing-safe'
const input = 'a'
const compareWith = 'bbbbbbbb'
timingSafeEqual(input, compareWith)
//> false
```

**Parameters**

| parameter | type           | description                          |
| --------- | -------------- | ------------------------------------ |
| `a`       | String, Buffer | String or buffer from input          |
| `b`       | String, Buffer | String or buffer to compare with `a` |

**Returns** `Boolean`, true if strings match

## Installation

Requires [nodejs](http://nodejs.org/).

```sh
$ npm install compare-timing-safe
```

## Tests

```sh
$ npm test
```

## License

Unlicense <https://unlicense.org>

## References

- [A lesson in timing attacks](https://codahale.com/a-lesson-in-timing-attacks/)

---
_Source: https://npm.io/package/compare-timing-safe · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
