Skip to content

Commit 6492f45

Browse files
committed
docs: update readme
1 parent 1a550e7 commit 6492f45

File tree

1 file changed

+82
-5
lines changed

1 file changed

+82
-5
lines changed

README.md

+82-5
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,113 @@
11
# react-native-bcrypt-cpp
22

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))
46

57
## Installation
68

79
```sh
810
npm install react-native-bcrypt-cpp
911
```
1012

13+
or
14+
15+
```sh
16+
yarn add react-native-bcrypt-cpp
17+
```
18+
1119
## Usage
1220

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)
1334

1435
```js
1536
import {
16-
generateHash,
1737
generateHashSync,
18-
validatePassword,
1938
validatePasswordSync,
2039
} from 'react-native-bcrypt-cpp';
2140

22-
// ...
41+
// Generate a hash synchronously
42+
const hash = generateHashSync('password', 12);
2343

44+
// Validate a password against a hash synchronously
45+
const isValid = validatePasswordSync('password', hash);
2446
```
2547

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.
26103

27104
## Contributing
28105

29106
See the [contributing guide](CONTRIBUTING.md) to learn how to contribute to the repository and the development workflow.
30107

31108
## License
32109

33-
MIT
110+
This project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details.
34111

35112
---
36113

0 commit comments

Comments
 (0)