summaryrefslogtreecommitdiffstats
path: root/src/global.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/global.cpp')
-rw-r--r--src/global.cpp23
1 files changed, 23 insertions, 0 deletions
diff --git a/src/global.cpp b/src/global.cpp
index 4efccad..ab2519b 100644
--- a/src/global.cpp
+++ b/src/global.cpp
@@ -7,6 +7,8 @@
#include <QDebug>
#include <QCoreApplication>
#include <QStringList>
+#include <QCryptographicHash>
+#include <QRegularExpression>
bool Global::m_testMode = false;
@@ -116,3 +118,24 @@ QStringList Global::urlWhitelist()
return QStringList();
return loadUrlList(path);
}
+
+void Global::writeCowToken(const QString &user, const QString &token)
+{
+ QString userHash = QString::fromLocal8Bit(QCryptographicHash::hash(user.toLocal8Bit(), QCryptographicHash::Md5).toHex());
+ QFile file(QLatin1String("/run/openslx/lightdm/") + userHash);
+ if (file.open(QFile::WriteOnly | QFile::Truncate)) {
+ file.write(token.toLocal8Bit());
+ file.close();
+ file.setPermissions(QFileDevice::ReadOwner | QFileDevice::WriteOwner);
+ }
+}
+
+bool Global::isValidShibCreds(const QString &ustr, const QString &upass)
+{
+ static QRegularExpression R_USER("^[a-z_A-Z][a-zA-Z0-9_@.-]{1,32}$");
+ static QRegularExpression R_PASS("^[a-z0-9]{1,32}$");
+
+ return ustr.contains('@')
+ && R_USER.match(ustr).hasMatch()
+ && R_PASS.match(upass).hasMatch();
+}