You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// Multiple calls within the same minute return identical codes
107
+
const code1 =generateMinutelyTwoFactor(6)
108
+
const code2 =generateMinutelyTwoFactor(6)
109
+
110
+
console.log(code1===code2) // true (within same minute)
111
+
```
112
+
113
+
## Algorithm
114
+
115
+
The function uses a deterministic algorithm to ensure consistency:
116
+
117
+
1.**Timestamp**: Gets current date/time in `yyyyMMddHHmm` format using `America/Santiago` timezone
118
+
2.**Calculation**: Applies formula `(timestamp * 97 + 31)`
119
+
3.**Formatting**: Adjusts result to requested length:
120
+
- If too short: pads with leading zeros
121
+
- If too long: takes the last N digits
122
+
123
+
## Technical Details
124
+
125
+
-**Consistency**: Same code generated throughout the entire minute
126
+
-**Uniqueness**: Different codes generated each minute
127
+
-**Format**: Numeric digits only (0-9)
128
+
-**Length**: Guaranteed to match the specified parameter
129
+
130
+
## Use Cases
131
+
132
+
- 🔐 Two-factor authentication systems
133
+
- ⏰ Time-based temporary codes
134
+
- 🔄 Multi-system code synchronization
135
+
136
+
## Timezone Considerations
137
+
138
+
The function specifically uses `America/Santiago` timezone to ensure consistent code generation regardless of the user's local timezone. This is important for applications that need to coordinate across different geographic locations.
0 commit comments