Generating username
This commit is contained in:
@@ -21,7 +21,7 @@ void GenerateConfirmation( char * number, int sz )
|
||||
|
||||
void GenerateConfirmationSeed( char * number, int sz, int seed )
|
||||
{
|
||||
char chars[] = "WRB01234WRB56789WRB";
|
||||
char chars[] = "WRB01234WRB56789WRBXQFDTYP";
|
||||
int n = sizeof(chars);
|
||||
int i;
|
||||
/*
|
||||
@@ -99,3 +99,30 @@ void GetOfferCode( unsigned long offer_id, char * number, int sz )
|
||||
pgsql_exec("COMMIT" ); // Unlock table 'data'
|
||||
strsafecpy( number, offer_code, sz );
|
||||
}
|
||||
|
||||
|
||||
void SetFamilyUsername( unsigned long family_id, char * number, int sz )
|
||||
{
|
||||
SQLINTEGER rows;
|
||||
char family_username[14];
|
||||
|
||||
// Lock table to prevent generation of two identical username
|
||||
pgsql_exec("BEGIN; LOCK TABLE members_family;" );
|
||||
int i = 0;
|
||||
do
|
||||
{
|
||||
GenerateConfirmationSeed( family_username, sizeof(family_username), i++ );
|
||||
|
||||
//st.CloseCursor();
|
||||
rows = 0;
|
||||
const PGresult *res = pgsql_query("SELECT id FROM members_family WHERE username='%s'", family_username );
|
||||
if (res!=NULL )
|
||||
{
|
||||
rows = pgsql_num_rows(res);
|
||||
}
|
||||
} while ( rows>0 && i<100 );
|
||||
|
||||
pgsql_exec("UPDATE members_family SET username='%s' WHERE id=%lu", family_username, family_id );
|
||||
pgsql_exec("COMMIT" ); // Unlock table 'data'
|
||||
strsafecpy( number, family_username, sz );
|
||||
}
|
||||
Reference in New Issue
Block a user