Skip to content
Snippets Groups Projects
Commit 9586a443 authored by Adrien Béraud's avatar Adrien Béraud
Browse files

PIN: increase size to 16 chars

Increases entropy from 41,36 bits to 82,72 bits.

GitLab: jami-project#1587
Change-Id: Ib5b73ef493963bfabaf87686ad22eccfd0079e31
parent 29184795
No related branches found
No related tags found
No related merge requests found
...@@ -653,15 +653,18 @@ ArchiveAccountManager::changePassword(const std::string& password_old, ...@@ -653,15 +653,18 @@ ArchiveAccountManager::changePassword(const std::string& password_old,
} }
std::string std::string
generatePIN(size_t length = 8) generatePIN(size_t length = 16, size_t split = 8)
{ {
static constexpr const char alphabet[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"; static constexpr const char alphabet[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
dht::crypto::random_device rd; dht::crypto::random_device rd;
std::uniform_int_distribution<size_t> dis(0, sizeof(alphabet) - 2); std::uniform_int_distribution<size_t> dis(0, sizeof(alphabet) - 2);
std::string ret; std::string ret;
ret.reserve(length); ret.reserve(length);
for (size_t i = 0; i < length; i++) for (size_t i = 0; i < length; i++) {
ret.push_back(alphabet[dis(rd)]); ret.push_back(alphabet[dis(rd)]);
if (i % split == split - 1 and i != length - 1)
ret.push_back('-');
}
return ret; return ret;
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment