I'm experiencing a very weird problem with Ohm that I'm not able to track and solve. Ohm version is 2.0.1.
This is my code:
class User < Ohm::Model
attribute :username
attribute :password
index :username
def password= string
@attributes[:password] = BCrypt::Password.create(string) # Tried self.password = BCrypt::whatever too
end
end
[15] pry(main)> User.find(username: 'test').first.password
=> "$2a$10$j1.s4hmuyCm8RffaEvB8IejaYOiZXWXId1Ccf8S0K3uXduxmMzyUq"
[16] pry(main)> User.find(username: 'test').first.password
=> "$2a$10$/0UzWtVsF.xczf4.UUqrP.PqYHxKs8fkIWKHlVVQVUNPFubzmuCwO"
[17] pry(main)> User.find(username: 'test').first.password
=> "$2a$10$ajlc3BYMOFXYDmy1a112ieXhMm39KoR1wPdPMp4WwEnxb2E35ypvC"
[18] pry(main)> User.find(username: 'test').first.password
=> "$2a$10$TlW87Gpd4RKpPutWzkePqeQiGri2ah.txDda4o6Lki7Sk1vayY9Fm"
Basically I'm able to set the password and encrypt it using BCrypt, but for some reasons every time I call the attribute the password is different. I have no idea what's happening here, can someone help me?