New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sqlite3: Binary data inserted for `string` type on column `crypted_password` #1121

Closed
WaYdotNET opened this Issue Mar 15, 2013 · 1 comment

Comments

Projects
None yet
2 participants
@WaYdotNET
Contributor

WaYdotNET commented Mar 15, 2013

Padrino edge, sqlite3, mini_record (or activerecord)

 % pdev rake seed                                                                                                                   
=> Executing Rake seed ...
  DEBUG -   (0.0ms)  select sqlite_version(*)
Which email do you want use for logging into admin? waydotnet@gmail.com
Tell me the password to use: testtest

  DEBUG -   (0.1ms)  begin transaction
  DEBUG -  Account Exists (0.6ms)  SELECT 1 AS one FROM "accounts" WHERE LOWER("accounts"."email") = LOWER('waydotnet@gmail.com') LIMIT 1
  ERROR -  Binary data inserted for `string` type on column `crypted_password`
  DEBUG -  SQL (0.4ms)  INSERT INTO "accounts" ("crypted_password", "email", "name", "role", "surname") VALUES (?, ?, ?, ?, ?)  [["crypted_password", "xxxxxxxxxxxxxxxx"], ["email", "waydotnet@gmail.com"], ["name", "Foo"], ["role", "admin"], ["surname", "Bar"]]
  DEBUG -   (131.9ms)  commit transaction
  DEBUG -  Account Exists (0.1ms)  SELECT 1 AS one FROM "accounts" WHERE (LOWER("accounts"."email") = LOWER('waydotnet@gmail.com') AND "accounts"."id" != 1) LIMIT 1

@dariocravero

This comment has been minimized.

Show comment
Hide comment
@dariocravero

dariocravero Mar 16, 2013

Contributor

Hey @WaYdotNET,

Looks like it's not really a bug; well, kind of, it's an encoding issue.

See this, the place where the error is logged and the fact that it doesn't really fail but it re-encodes the string to utf-8.

Here's a better explanation sparklemotion/sqlite3-ruby#45 and the Stack Overflow post that led me there.

See, if I try this (console's output):

irb(main):008:0> acc=Account.new(name: "dario", surname: "cravero", email: "dario@uxtemple.com", role: "admin", password: "dario", password_confirmation: "dario")
=> #<Account id: nil, name: "dario", surname: "cravero", email: "dario@uxtemple.com", crypted_password: nil, role: "admin", created_at: nil, updated_at: nil>
irb(main):009:0> acc.save
  DEBUG -   (0.1ms)  begin transaction
  DEBUG -  Account Exists (0.2ms)  SELECT 1 AS one FROM "accounts" WHERE LOWER("accounts"."email") = LOWER('dario@uxtemple.com') LIMIT 1
  ERROR -  Binary data inserted for `string` type on column `crypted_password`
  DEBUG -  SQL (0.6ms)  INSERT INTO "accounts" ("created_at", "crypted_password", "email", "name", "role", "surname", "updated_at") VALUES (?, ?, ?, ?, ?, ?, ?)  [["created_at", 2013-03-15 21:18:28 -0300], ["crypted_password", "$2a$10$nEHc1M1sD/1ZXVKu.GVbg.pT8GWiEaxe6ep7mIBkaYNP86rxLqSNu"], ["email", "dario@uxtemple.com"], ["name", "dario"], ["role", "admin"], ["surname", "cravero"], ["updated_at", 2013-03-15 21:18:28 -0300]]
  DEBUG -   (1.0ms)  commit transaction
=> true
irb(main):010:0> acc.crypted_password.encoding
=> #<Encoding:ASCII-8BIT>

It's a tricky one, if we force crypted_password to be encoded as utf-8 in here it will fail with this BCrypt::Errors::InvalidSalt: invalid salt.

Thoughts @padrino/core-members?

Contributor

dariocravero commented Mar 16, 2013

Hey @WaYdotNET,

Looks like it's not really a bug; well, kind of, it's an encoding issue.

See this, the place where the error is logged and the fact that it doesn't really fail but it re-encodes the string to utf-8.

Here's a better explanation sparklemotion/sqlite3-ruby#45 and the Stack Overflow post that led me there.

See, if I try this (console's output):

irb(main):008:0> acc=Account.new(name: "dario", surname: "cravero", email: "dario@uxtemple.com", role: "admin", password: "dario", password_confirmation: "dario")
=> #<Account id: nil, name: "dario", surname: "cravero", email: "dario@uxtemple.com", crypted_password: nil, role: "admin", created_at: nil, updated_at: nil>
irb(main):009:0> acc.save
  DEBUG -   (0.1ms)  begin transaction
  DEBUG -  Account Exists (0.2ms)  SELECT 1 AS one FROM "accounts" WHERE LOWER("accounts"."email") = LOWER('dario@uxtemple.com') LIMIT 1
  ERROR -  Binary data inserted for `string` type on column `crypted_password`
  DEBUG -  SQL (0.6ms)  INSERT INTO "accounts" ("created_at", "crypted_password", "email", "name", "role", "surname", "updated_at") VALUES (?, ?, ?, ?, ?, ?, ?)  [["created_at", 2013-03-15 21:18:28 -0300], ["crypted_password", "$2a$10$nEHc1M1sD/1ZXVKu.GVbg.pT8GWiEaxe6ep7mIBkaYNP86rxLqSNu"], ["email", "dario@uxtemple.com"], ["name", "dario"], ["role", "admin"], ["surname", "cravero"], ["updated_at", 2013-03-15 21:18:28 -0300]]
  DEBUG -   (1.0ms)  commit transaction
=> true
irb(main):010:0> acc.crypted_password.encoding
=> #<Encoding:ASCII-8BIT>

It's a tricky one, if we force crypted_password to be encoded as utf-8 in here it will fail with this BCrypt::Errors::InvalidSalt: invalid salt.

Thoughts @padrino/core-members?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment