|
1 | 1 | # react-native-bcrypt-cpp
|
2 | 2 |
|
3 |
| -Bcrypt implemented in pure C++ and linked to React Native using Turbo Modules |
| 3 | +Next-gen React Native library for Bcrypt hashing using pure C++ with Turbo Modules and multithreading for superior performance. |
| 4 | + |
| 5 | +**_NOTE:_** This library can be used only with New Architecture (more information about New Architecture [here](https://github.com/reactwg/react-native-new-architecture)) |
4 | 6 |
|
5 | 7 | ## Installation
|
6 | 8 |
|
7 | 9 | ```sh
|
8 | 10 | npm install react-native-bcrypt-cpp
|
9 | 11 | ```
|
10 | 12 |
|
| 13 | +or |
| 14 | + |
| 15 | +```sh |
| 16 | +yarn add react-native-bcrypt-cpp |
| 17 | +``` |
| 18 | + |
11 | 19 | ## Usage
|
12 | 20 |
|
| 21 | +### Asynchronous Hashing (Multithreaded) |
| 22 | + |
| 23 | +```js |
| 24 | +import { generateHash, validatePassword } from 'react-native-bcrypt-cpp'; |
| 25 | + |
| 26 | +// Generate a hash asynchronously |
| 27 | +const hash = await generateHash('password', 12); |
| 28 | + |
| 29 | +// Validate a password against a hash |
| 30 | +const isValid = await validatePassword('password', hash); |
| 31 | +``` |
| 32 | + |
| 33 | +### Synchronous Hashing (Single-threaded) |
13 | 34 |
|
14 | 35 | ```js
|
15 | 36 | import {
|
16 |
| - generateHash, |
17 | 37 | generateHashSync,
|
18 |
| - validatePassword, |
19 | 38 | validatePasswordSync,
|
20 | 39 | } from 'react-native-bcrypt-cpp';
|
21 | 40 |
|
22 |
| -// ... |
| 41 | +// Generate a hash synchronously |
| 42 | +const hash = generateHashSync('password', 12); |
23 | 43 |
|
| 44 | +// Validate a password against a hash synchronously |
| 45 | +const isValid = validatePasswordSync('password', hash); |
24 | 46 | ```
|
25 | 47 |
|
| 48 | +## API Reference |
| 49 | + |
| 50 | +## API Reference |
| 51 | + |
| 52 | +### `generateHash(password: string, workload: number): Promise<string>` |
| 53 | + |
| 54 | +Asynchronously generates a Bcrypt hash for the given password with the specified workload factor. |
| 55 | + |
| 56 | +**Parameters:** |
| 57 | + |
| 58 | +- `password` (string): The password to hash. |
| 59 | +- `workload` (number): The cost factor for the hashing algorithm (e.g., 12). |
| 60 | + |
| 61 | +**Returns:** |
| 62 | + |
| 63 | +- A `Promise` that resolves to a `string` containing the generated hash. |
| 64 | + |
| 65 | +### `validatePassword(password: string, hash: string): Promise<boolean>` |
| 66 | + |
| 67 | +Asynchronously validates the given password against the Bcrypt hash. |
| 68 | + |
| 69 | +**Parameters:** |
| 70 | + |
| 71 | +- `password` (string): The password to validate. |
| 72 | +- `hash` (string): The Bcrypt hash to validate against. |
| 73 | + |
| 74 | +**Returns:** |
| 75 | + |
| 76 | +- A `Promise` that resolves to a `boolean` indicating whether the password is valid. |
| 77 | + |
| 78 | +### `generateHashSync(password: string, workload: number): string` |
| 79 | + |
| 80 | +Synchronously generates a Bcrypt hash for the given password with the specified workload factor. |
| 81 | + |
| 82 | +**Parameters:** |
| 83 | + |
| 84 | +- `password` (string): The password to hash. |
| 85 | +- `workload` (number): The cost factor for the hashing algorithm (e.g., 12). |
| 86 | + |
| 87 | +**Returns:** |
| 88 | + |
| 89 | +- A `string` containing the generated hash. |
| 90 | + |
| 91 | +### `validatePasswordSync(password: string, hash: string): boolean` |
| 92 | + |
| 93 | +Synchronously validates the given password against the Bcrypt hash. |
| 94 | + |
| 95 | +**Parameters:** |
| 96 | + |
| 97 | +- `password` (string): The password to validate. |
| 98 | +- `hash` (string): The Bcrypt hash to validate against. |
| 99 | + |
| 100 | +**Returns:** |
| 101 | + |
| 102 | +- A `boolean` indicating whether the password is valid. |
26 | 103 |
|
27 | 104 | ## Contributing
|
28 | 105 |
|
29 | 106 | See the [contributing guide](CONTRIBUTING.md) to learn how to contribute to the repository and the development workflow.
|
30 | 107 |
|
31 | 108 | ## License
|
32 | 109 |
|
33 |
| -MIT |
| 110 | +This project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details. |
34 | 111 |
|
35 | 112 | ---
|
36 | 113 |
|
|
0 commit comments