+ user.password = hash
+
+ return next()
+ })
+}
+
+// ------------------------------ METHODS ------------------------------
+
+function isPasswordMatch (password, callback) {
+ return peertubeCrypto.comparePassword(password, this.password, callback)
+}
+
+function toFormatedJSON () {
+ return {
+ id: this.id,
+ username: this.username,
+ role: this.role,
+ createdAt: this.createdAt
+ }
+}
+// ------------------------------ STATICS ------------------------------
+
+function associate (models) {
+ this.hasOne(models.Author, {
+ foreignKey: 'userId',
+ onDelete: 'cascade'
+ })
+
+ this.hasMany(models.OAuthToken, {
+ foreignKey: 'userId',
+ onDelete: 'cascade'
+ })
+}
+
+function countTotal (callback) {
+ return this.count().asCallback(callback)
+}
+
+function getByUsername (username) {
+ const query = {
+ where: {
+ username: username
+ }
+ }
+
+ return this.findOne(query)
+}