Commit 3db50925 authored by unknown's avatar unknown

SCRUM

Add optional second parameter to password() function. It can be used to force password()
to return fixed values. 


mysql-test/r/func_crypt.result:
  New test results
mysql-test/t/func_crypt.test:
  new tests
sql/item_strfunc.cc:
  Add optional second argument to password() function
sql/item_strfunc.h:
  New method
sql/sql_yacc.yy:
  Handling of password with 2 arguments
parent c917474e
select length(encrypt('foo', 'ff')) <> 0; select length(encrypt('foo', 'ff')) <> 0;
length(encrypt('foo', 'ff')) <> 0 length(encrypt('foo', 'ff')) <> 0
1 1
select old_password('test'),length(password("1")),length(encrypt('test')),encrypt('test','aa'); select password("a",""), password("a",NULL), password("","a"), password(NULL,"a");
password("a","") password("a",NULL) password("","a") password(NULL,"a")
*2517f7235d68d4ba2e5019c93420523101157a792c01 NULL NULL
select password("aaaaaaaaaaaaaaaa","a"), password("a","aaaaaaaaaaaaaaaa");
password("aaaaaaaaaaaaaaaa","a") password("a","aaaaaaaaaaaaaaaa")
*2cd3b9a44e9a9994789a30f935c92f45a96c5472f381 *37c7c5c794ff144819f2531bf03c57772cd84e40db09
select old_password('test'), length(password("1")), length(encrypt('test')), encrypt('test','aa');
old_password('test') length(password("1")) length(encrypt('test')) encrypt('test','aa') old_password('test') length(password("1")) length(encrypt('test')) encrypt('test','aa')
378b243e220ca493 45 13 aaqPiZY5xR5l. 378b243e220ca493 45 13 aaqPiZY5xR5l.
select old_password(""), old_password(NULL), password(""), password(NULL);
old_password("") old_password(NULL) password("") password(NULL)
NULL NULL
select length(encrypt('foo', 'ff')) <> 0; select length(encrypt('foo', 'ff')) <> 0;
--replace_result $1$aa$4OSUA5cjdx0RUQ08opV27/ aaqPiZY5xR5l. --replace_result $1$aa$4OSUA5cjdx0RUQ08opV27/ aaqPiZY5xR5l.
select old_password('test'),length(password("1")),length(encrypt('test')),encrypt('test','aa');
# Test new and old password handling functions
select password("a",""), password("a",NULL), password("","a"), password(NULL,"a");
select password("aaaaaaaaaaaaaaaa","a"), password("a","aaaaaaaaaaaaaaaa");
select old_password('test'), length(password("1")), length(encrypt('test')), encrypt('test','aa');
select old_password(""), old_password(NULL), password(""), password(NULL);
...@@ -1271,18 +1271,52 @@ String *Item_func_trim::val_str(String *str) ...@@ -1271,18 +1271,52 @@ String *Item_func_trim::val_str(String *str)
return &tmp_value; return &tmp_value;
} }
/*
Password() function can have 2 args now. Second argument can be used
to make results repeatable
*/
String *Item_func_password::val_str(String *str) String *Item_func_password::val_str(String *str)
{ {
String *res =args[0]->val_str(str); struct rand_struct rand_st; // local structure for 2 param version
ulong seed=0; // seed to initialise random generator to
if ((null_value=args[0]->null_value)) if ((null_value=args[0]->null_value))
return 0; return 0;
if (arg_count == 1)
{
String *res =args[0]->val_str(str);
if (res->length() == 0) if (res->length() == 0)
return &empty_string; return &empty_string;
make_scrambled_password(tmp_value,res->c_ptr(),opt_old_passwords, make_scrambled_password(tmp_value,res->c_ptr(),opt_old_passwords,
&current_thd->rand); &current_thd->rand);
str->set(tmp_value,get_password_length(opt_old_passwords),res->charset()); str->set(tmp_value,get_password_length(opt_old_passwords),res->charset());
return str; return str;
}
else
{
/* Check second argument for NULL value. First one is already checked */
if ((null_value=args[1]->null_value))
return 0;
/* Generate the seed first this allows to avoid double allocation */
char* seed_ptr=args[1]->val_str(str)->c_ptr();
while (*seed_ptr)
{
seed=seed*211+*seed_ptr; /* Use simple hashing */
seed_ptr++;
}
/* Use constants which allow nice random values even with small seed */
randominit(&rand_st,seed*111111+33333333L,seed*1111+55555555L);
String *res =args[0]->val_str(str);
if (res->length() == 0)
return &empty_string;
make_scrambled_password(tmp_value,res->c_ptr(),opt_old_passwords,
&rand_st);
str->set(tmp_value,get_password_length(opt_old_passwords),res->charset());
return str;
}
} }
String *Item_func_old_password::val_str(String *str) String *Item_func_old_password::val_str(String *str)
......
...@@ -257,6 +257,7 @@ class Item_func_password :public Item_str_func ...@@ -257,6 +257,7 @@ class Item_func_password :public Item_str_func
char tmp_value[64]; /* This should be enough for new password format */ char tmp_value[64]; /* This should be enough for new password format */
public: public:
Item_func_password(Item *a) :Item_str_func(a) {} Item_func_password(Item *a) :Item_str_func(a) {}
Item_func_password(Item *a, Item *b) :Item_str_func(a,b) {}
String *val_str(String *); String *val_str(String *);
void fix_length_and_dec() { max_length = get_password_length(opt_old_passwords); } void fix_length_and_dec() { max_length = get_password_length(opt_old_passwords); }
const char *func_name() const { return "password"; } const char *func_name() const { return "password"; }
......
...@@ -2201,9 +2201,9 @@ simple_expr: ...@@ -2201,9 +2201,9 @@ simple_expr:
| NOW_SYM '(' expr ')' | NOW_SYM '(' expr ')'
{ $$= new Item_func_now($3); Lex->safe_to_cache_query=0;} { $$= new Item_func_now($3); Lex->safe_to_cache_query=0;}
| PASSWORD '(' expr ')' | PASSWORD '(' expr ')'
{ { $$= new Item_func_password($3); }
$$= new Item_func_password($3); | PASSWORD '(' expr ',' expr ')'
} { $$= new Item_func_password($3,$5); }
| POINTFROMTEXT '(' expr ')' | POINTFROMTEXT '(' expr ')'
{ $$= new Item_func_geometry_from_text($3); } { $$= new Item_func_geometry_from_text($3); }
| POINTFROMTEXT '(' expr ',' expr ')' | POINTFROMTEXT '(' expr ',' expr ')'
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment