1
/* Copyright (C) 2010 Rackspace
3
This program is free software; you can redistribute it and/or modify
4
it under the terms of the GNU General Public License as published by
5
the Free Software Foundation; version 2 of the License.
7
This program is distributed in the hope that it will be useful,
8
but WITHOUT ANY WARRANTY; without even the implied warranty of
9
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10
GNU General Public License for more details.
12
You should have received a copy of the GNU General Public License
13
along with this program; if not, write to the Free Software
14
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
17
#include "mysql_password.h"
18
#include "drizzled/algorithm/sha1.h"
19
#include "drizzled/util/convert.h"
22
using namespace drizzled;
24
const char* MySQLPasswordName = "mysql_password";
26
MySQLPassword::MySQLPassword(void):
30
const char *MySQLPassword::func_name() const
32
return MySQLPasswordName;
35
void MySQLPassword::fix_length_and_dec()
37
max_length= args[0]->max_length;
40
bool MySQLPassword::check_argument_count(int n)
45
String *MySQLPassword::val_str(String *str)
48
String *password= args[0]->val_str(&argument);
50
uint8_t hash_tmp1[SHA1_DIGEST_LENGTH];
51
uint8_t hash_tmp2[SHA1_DIGEST_LENGTH];
54
SHA1Update(&ctx, reinterpret_cast<uint8_t *>(password->ptr()),
56
SHA1Final(hash_tmp1, &ctx);
59
SHA1Update(&ctx, hash_tmp1, SHA1_DIGEST_LENGTH);
60
SHA1Final(hash_tmp2, &ctx);
62
str->realloc(SHA1_DIGEST_LENGTH * 2);
63
drizzled_string_to_hex(str->ptr(), reinterpret_cast<const char*>(hash_tmp2),
65
str->length(SHA1_DIGEST_LENGTH * 2);