| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 // | 4 // |
| 5 // This class isn't pretty. It's just a step better than globals, which is what | 5 // This class isn't pretty. It's just a step better than globals, which is what |
| 6 // these were previously. | 6 // these were previously. |
| 7 | 7 |
| 8 #include "chrome/browser/sync/util/user_settings.h" | 8 #include "chrome/browser/sync/util/user_settings.h" |
| 9 | 9 |
| 10 #include "build/build_config.h" | 10 #include "build/build_config.h" |
| (...skipping 339 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 350 | 350 |
| 351 void UserSettings::StoreHashedPassword(const string& email, | 351 void UserSettings::StoreHashedPassword(const string& email, |
| 352 const string& password) { | 352 const string& password) { |
| 353 // Save one-way hashed password: | 353 // Save one-way hashed password: |
| 354 char binary_salt[kSaltSize]; | 354 char binary_salt[kSaltSize]; |
| 355 base::RandBytes(binary_salt, sizeof(binary_salt)); | 355 base::RandBytes(binary_salt, sizeof(binary_salt)); |
| 356 | 356 |
| 357 const string salt = APEncode(string(binary_salt, sizeof(binary_salt))); | 357 const string salt = APEncode(string(binary_salt, sizeof(binary_salt))); |
| 358 base::MD5Context md5_context; | 358 base::MD5Context md5_context; |
| 359 base::MD5Init(&md5_context); | 359 base::MD5Init(&md5_context); |
| 360 base::MD5Update(&md5_context, salt.data(), salt.size()); | 360 base::MD5Update(&md5_context, salt); |
| 361 base::MD5Update(&md5_context, password.data(), password.size()); | 361 base::MD5Update(&md5_context, password); |
| 362 base::MD5Digest md5_digest; | 362 base::MD5Digest md5_digest; |
| 363 base::MD5Final(&md5_digest, &md5_context); | 363 base::MD5Final(&md5_digest, &md5_context); |
| 364 | 364 |
| 365 ScopedDBHandle dbhandle(this); | 365 ScopedDBHandle dbhandle(this); |
| 366 SQLTransaction transaction(dbhandle.get()); | 366 SQLTransaction transaction(dbhandle.get()); |
| 367 transaction.BeginExclusive(); | 367 transaction.BeginExclusive(); |
| 368 { | 368 { |
| 369 SQLStatement statement; | 369 SQLStatement statement; |
| 370 statement.prepare(dbhandle.get(), | 370 statement.prepare(dbhandle.get(), |
| 371 "INSERT INTO settings(email, key, value)" | 371 "INSERT INTO settings(email, key, value)" |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 413 salt = query.column_string(1); | 413 salt = query.column_string(1); |
| 414 else | 414 else |
| 415 hash = query.column_int(1); | 415 hash = query.column_int(1); |
| 416 query_result = query.step(); | 416 query_result = query.step(); |
| 417 } | 417 } |
| 418 CHECK(SQLITE_DONE == query_result); | 418 CHECK(SQLITE_DONE == query_result); |
| 419 if (salt.empty() || hash == kInvalidHash) | 419 if (salt.empty() || hash == kInvalidHash) |
| 420 return false; | 420 return false; |
| 421 base::MD5Context md5_context; | 421 base::MD5Context md5_context; |
| 422 base::MD5Init(&md5_context); | 422 base::MD5Init(&md5_context); |
| 423 base::MD5Update(&md5_context, salt.data(), salt.size()); | 423 base::MD5Update(&md5_context, salt); |
| 424 base::MD5Update(&md5_context, password.data(), password.size()); | 424 base::MD5Update(&md5_context, password); |
| 425 base::MD5Digest md5_digest; | 425 base::MD5Digest md5_digest; |
| 426 base::MD5Final(&md5_digest, &md5_context); | 426 base::MD5Final(&md5_digest, &md5_context); |
| 427 return hash == GetHashFromDigest(md5_digest); | 427 return hash == GetHashFromDigest(md5_digest); |
| 428 } | 428 } |
| 429 | 429 |
| 430 void UserSettings::SwitchUser(const string& username) { | 430 void UserSettings::SwitchUser(const string& username) { |
| 431 { | 431 { |
| 432 base::AutoLock lock(mutex_); | 432 base::AutoLock lock(mutex_); |
| 433 email_ = username; | 433 email_ = username; |
| 434 } | 434 } |
| (...skipping 21 matching lines...) Expand all Loading... |
| 456 query.prepare(dbhandle.get(), "SELECT email FROM cookies"); | 456 query.prepare(dbhandle.get(), "SELECT email FROM cookies"); |
| 457 if (SQLITE_ROW == query.step()) { | 457 if (SQLITE_ROW == query.step()) { |
| 458 *username = query.column_string(0); | 458 *username = query.column_string(0); |
| 459 return true; | 459 return true; |
| 460 } else { | 460 } else { |
| 461 return false; | 461 return false; |
| 462 } | 462 } |
| 463 } | 463 } |
| 464 | 464 |
| 465 } // namespace browser_sync | 465 } // namespace browser_sync |
| OLD | NEW |