1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
|
// Copyright (c) 2008 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/webdata/web_database.h"
#include "base/logging.h"
#include "base/time.h"
#include "chrome/browser/password_manager/ie7_password.h"
#include "chrome/common/sqlite_utils.h"
bool WebDatabase::AddIE7Login(const IE7PasswordInfo& info) {
SQLStatement s;
if (s.prepare(db_,
"INSERT OR REPLACE INTO ie7_logins "
"(url_hash, password_value, date_created) "
"VALUES (?, ?, ?)") != SQLITE_OK) {
NOTREACHED() << "Statement prepare failed";
return false;
}
s.bind_wstring(0, info.url_hash);
s.bind_blob(1, &info.encrypted_data.front(),
static_cast<int>(info.encrypted_data.size()));
s.bind_int64(2, info.date_created.ToTimeT());
if (s.step() != SQLITE_DONE) {
NOTREACHED();
return false;
}
return true;
}
bool WebDatabase::RemoveIE7Login(const IE7PasswordInfo& info) {
SQLStatement s;
// Remove a login by UNIQUE-constrained fields.
if (s.prepare(db_,
"DELETE FROM ie7_logins WHERE "
"url_hash = ?") != SQLITE_OK) {
NOTREACHED() << "Statement prepare failed";
return false;
}
s.bind_wstring(0, info.url_hash);
if (s.step() != SQLITE_DONE) {
NOTREACHED();
return false;
}
return true;
}
bool WebDatabase::GetIE7Login(const IE7PasswordInfo& info,
IE7PasswordInfo* result) {
DCHECK(result);
SQLStatement s;
if (s.prepare(db_,
"SELECT password_value, date_created FROM ie7_logins "
"WHERE url_hash == ? ") != SQLITE_OK) {
NOTREACHED() << "Statement prepare failed";
return false;
}
s.bind_wstring(0, info.url_hash);
int64 query_result = s.step();
if (query_result == SQLITE_ROW) {
s.column_blob_as_vector(0, &result->encrypted_data);
result->date_created = base::Time::FromTimeT(s.column_int64(1));
result->url_hash = info.url_hash;
s.step();
}
return query_result == SQLITE_DONE;
}
|