Skip to content

Commit

Permalink
Generate more user friendly SHV API key
Browse files Browse the repository at this point in the history
  • Loading branch information
Fanda Vacek committed Jul 4, 2024
1 parent 3a55887 commit 702a0ac
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 10 deletions.
2 changes: 1 addition & 1 deletion 3rdparty/libshv
26 changes: 19 additions & 7 deletions quickevent/app/quickevent/plugins/Event/src/eventplugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -511,13 +511,25 @@ QString EventPlugin::shvApiEventId() const
QString EventPlugin::createShvApiKey()
{
QString key;
QList<char> cc;
for (auto i = 'a'; i <= 'z'; i++) { cc << i; }
for (auto i = 'A'; i <= 'Z'; i++) { cc << i; }
for (auto i = '0'; i <= '9'; i++) { cc << i; }
for (int i = 0; i < 16; i++) {
quint32 ix = QRandomGenerator::global()->generate() % cc.size();
key += cc[ix];
static const QList<char> vowels{'a', 'e', 'i', 'o', 'u', 'y'};
static const QList<char> consonants = []() {
QList<char> cc;
for (auto i = 'a'; i <= 'z'; i++) {
if (!vowels.contains(i)) {
cc << i;
}
}
return cc;
} ();
for (int i = 0; i < 12; i++) {
if (i % 2 == 0) {
auto ix = QRandomGenerator::global()->generate() % consonants.size();
key += consonants[ix];
}
else {
auto ix = QRandomGenerator::global()->generate() % vowels.size();
key += vowels[ix];
}
}
return key;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,12 @@ bool ShvClientServiceWidget::saveSettings()
void ShvClientServiceWidget::updateQrCodeUrl()
{
QUrl url(ui->shvUrl->text());
url.setScheme("https");
url.setPath("/" + ui->shvEventPath->text());
auto query = QUrlQuery(url);
url.setQuery(QString());
query.addQueryItem("api_key", ui->shvApiKey->text());
url.setQuery(query);
bool b = url.isValid();
auto es = url.errorString();
auto s = url.toString();
ui->qrCodeUrl->setText(s);
}
Expand Down

0 comments on commit 702a0ac

Please sign in to comment.