MongoMetaRecord MegaProtoUser 登錄時密碼未散列 (MongoMetaRecord MegaProtoUser Password not hashed when signing in)


問題描述

MongoMetaRecord MegaProtoUser 登錄時密碼未散列 (MongoMetaRecord MegaProtoUser Password not hashed when signing in)

I am using the MegaProtoUser in my Lift/Scala app for managing users.

On my running app, I can sign up with a new user normally and he remains singed in just after sign up. After I log out and try logging in with the same user name and password, the app complains that the username/password is invalid.

I checked the mongo database entry for the password field and found that the password is hashed.

If I copy and paste the the hashed password the mongo database directly in the password field of the web app, the user is logged in. Password in the database looks like this: oqGR/cR+phb7fpSOL1Bpi8mtV...

Code for model.User.scala:

/**
 * The singleton that has methods for accessing the database
 */
object User extends User with MongoMetaRecord[User] with MetaMegaProtoUser[User] {
  override def screenWrap = Full(<lift:surround with="default" at="content">
      <lift:bind /></lift:surround>)
  // define the order fields will appear in forms and output
  override def fieldOrder = List(id, firstName, lastName, email,
                                 locale, timezone, password)

  // comment this line out to require email validations
  override def skipEmailValidation = true

}

/**
 * An O-R mapped "User" class that includes first name, last name, password and we add a "Personal Essay" to it
 */
class User private() extends MongoRecord[User] with MegaProtoUser[User] {
  def meta = User // what's the "meta" server
  protected def userFromStringId(id: String): Box[User] = meta.find(id)

  protected def findUserByUniqueId(id: String): Box[User] =  {
    var searchListHeadOption = meta.findAll("_id",id).headOption
    searchListHeadOption match {
      case Some(x) => Full(x)
      case None => return Empty
    }
  }
  /**
   * Given an username (probably email address), find the user
   */
  protected def findUserByEmail(email: String): Box[User] = {
    var searchListHeadOption = meta.findAll("email",email).headOption
    searchListHeadOption match {
      case Some(x) => Full(x)
      case None => return Empty
    }
  }


  protected def findUserByUserName(email: String): Box[User] = findUserByEmail(email)

  override def valUnique(errorMsg: => String)(emailValue: String) = {
    meta.findAll("email",emailValue) match {
      case Nil => Nil
      case usr :: Nil if (usr.id == id) => Nil
      case _ => List(FieldError(email, "The email should be unique"))
    }
  }

  // define an additional field for a personal essay
}

When logging in, the entered password is matched with the hashed password from the db. I am kind of stuck at this point. 

Any help would be appreciated.

Thanks!


參考解法

方法 1:

I saw similar Lift issue regarding Record's PasswordField open. Hope it helps!

(by seekerlester)

參考文件

  1. MongoMetaRecord MegaProtoUser Password not hashed when signing in (CC BY-SA 3.0/4.0)

#mongoDB #lift #scala






相關問題

將 (.net) BsonDocument 字符串轉換為 (java) DBObject (Converting (.net) BsonDocument string into a (java) DBObject)

Mongo 客戶端出錯 (Error with Mongo Client)

對列表進行排序並在 mongodb 中插入一個新列 (Sort the list and insert a new column in mongodb)

無法導入示例數據集(系統找不到指定文件) (Cannot import example dataset (the system cannot find the specified file))

mongodb c#更新嵌入文檔 (mongodb c# update embedded document)

查詢嵌入列表中的數組 (Querying for array in embedded list)

搜索條件的mongodb map reduce (mongodb map reduce for search criteria)

org.bson.codecs.configuration.CodecConfigurationException:找不到類 [Ljava.lang.String; 的編解碼器; (org.bson.codecs.configuration.CodecConfigurationException: Can't find a codec for class [Ljava.lang.String;)

在碼頭上部署 gwt Web 應用程序 (deploying gwt web application on jetty)

MongoMetaRecord MegaProtoUser 登錄時密碼未散列 (MongoMetaRecord MegaProtoUser Password not hashed when signing in)

將 mongo shell 連接到受限的 MongoDB Atlas 數據庫? (Connect mongo shell to restricted MongoDB Atlas Database?)

用於 $or 和 $and 場景的 $elemMatch 數組 (Arrays working $elemMatch for $or and $and scenarios)







留言討論