Add authenticator column to quasseluser table
[quassel.git] / src / core / storage.h
index 62de488..29a8df8 100644 (file)
@@ -1,5 +1,5 @@
 /***************************************************************************
- *   Copyright (C) 2005-2012 by the Quassel Project                        *
+ *   Copyright (C) 2005-2016 by the Quassel Project                        *
  *   devel@quassel-irc.org                                                 *
  *                                                                         *
  *   This program is free software; you can redistribute it and/or modify  *
@@ -42,6 +42,13 @@ public:
         NotAvailable // remove the storage backend from the list of avaliable backends
     };
 
+    enum HashVersion {
+        Sha1,
+        Sha2_512,
+        Latest=Sha2_512
+        
+    };
+
 public slots:
     /* General */
 
@@ -96,7 +103,7 @@ public slots:
      *  \param password The cleartext password for the new user
      *  \return The new user's UserId
      */
-    virtual UserId addUser(const QString &user, const QString &password) = 0;
+    virtual UserId addUser(const QString &user, const QString &password, const QString &authenticator = "Database") = 0;
 
     //! Update a core user's password.
     /** \param user     The user's id
@@ -124,6 +131,13 @@ public slots:
      */
     virtual UserId getUserId(const QString &username) = 0;
 
+    //! Get the authentication provider for a given user.
+    /** \param username  The username to validate
+     *  \return The name of the auth provider if the UserId exists, "" otherwise.
+     */
+    virtual QString getUserAuthenticator(const UserId userid) = 0;
+
+
     //! Determine the UserId of the internal user
     /** \return A valid UserId if the password matches the username; 0 else
      */
@@ -408,10 +422,16 @@ signals:
     void userRemoved(UserId);
 
 protected:
-    //! when implementing a storage handler, use this method to crypt user passwords.
-    /**  This guarantees compatibility with other storage handlers and allows easy migration
-     */
-    QString cryptedPassword(const QString &password);
+    QString hashPassword(const QString &password);
+    bool checkHashedPassword(const UserId user, const QString &password, const QString &hashedPassword, const Storage::HashVersion version);
+
+private:
+    QString hashPasswordSha1(const QString &password);
+    bool checkHashedPasswordSha1(const QString &password, const QString &hashedPassword);
+
+    QString hashPasswordSha2_512(const QString &password);
+    bool checkHashedPasswordSha2_512(const QString &password, const QString &hashedPassword);
+    QString sha2_512(const QString &input);
 };