]> granicus.if.org Git - php/commitdiff
Adding function to change user passwords
authorFrank M. Kromann <fmk@php.net>
Thu, 26 Feb 2004 20:31:14 +0000 (20:31 +0000)
committerFrank M. Kromann <fmk@php.net>
Thu, 26 Feb 2004 20:31:14 +0000 (20:31 +0000)
ext/fbsql/php_fbsql.c
ext/fbsql/php_fbsql.h

index f55869345d0705dc205f42fc81c795c09682c7c9..de5baa2473e429ffc7a729e10c0575b754b7f819 100644 (file)
@@ -163,6 +163,21 @@ struct PHPFBLink
 #define FBSQL_LOB_DIRECT 0                             /* default */
 #define FBSQL_LOB_HANDLE 1                             /* default */
 
+int mdOk(PHPFBLink* link, FBCMetaData* md, char* sql);
+char *DigestPassword(char *user, char *password)
+{
+       char *digest = NULL;
+
+       if (user && strlen(user) && password && strlen(password)) {
+               char *user_upper = estrdup(user);
+               digest = emalloc(17);
+               digest[0] = '\0';
+               (void)fbcDigestPassword(php_strtoupper(user_upper, strlen(user_upper)), password, digest);
+               efree(user_upper);
+       }
+
+       return digest;
+}
 
 /* {{{ fbsql_functions[]
  */
@@ -225,6 +240,7 @@ function_entry fbsql_functions[] = {
        PHP_FE(fbsql_username,          NULL)
        PHP_FE(fbsql_password,          NULL)
        PHP_FE(fbsql_warnings,          NULL)
+       PHP_FE(fbsql_set_password,              NULL)
 
        PHP_FE(fbsql_get_autostart_info,        NULL)
 /*     PHP_FE(fbsql_set_autostart_info,        NULL) */
@@ -1319,6 +1335,48 @@ PHP_FUNCTION(fbsql_password)
 }
 /* }}} */
 
+/* {{{ proto bool fbsql_set_password(resource link_identifier, string user, string password, string old_password)
+   Change the password for a given user */
+PHP_FUNCTION(fbsql_set_password)
+{
+       PHPFBLink* phpLink = NULL;
+       zval **fbsql_link_index = NULL, **user, **password, **old_password;
+       char *digest_password, *digest_old_password;
+       FBCMetaData *md;
+       
+       switch (ZEND_NUM_ARGS()) {
+               case 4:
+                       if (zend_get_parameters_ex(4, &fbsql_link_index, &user, &password, &old_password)==FAILURE) {
+                               RETURN_FALSE;
+                       }
+                       break;
+               default:
+                       WRONG_PARAM_COUNT;
+                       break;
+       }
+       ZEND_FETCH_RESOURCE2(phpLink, PHPFBLink *, fbsql_link_index, -1, "FrontBase-Link", le_link, le_plink);
+
+       convert_to_string_ex(user);
+       convert_to_string_ex(password);
+       convert_to_string_ex(old_password);
+
+       digest_password = DigestPassword(Z_STRVAL_PP(user), Z_STRVAL_PP(password));
+       digest_old_password = DigestPassword(Z_STRVAL_PP(user), Z_STRVAL_PP(old_password));
+
+       md = fbcdcSetPasswordForUser(phpLink->connection, Z_STRVAL_PP(user), digest_password, digest_old_password);
+       if (mdOk(phpLink, md, "Change password")) {
+               ZVAL_BOOL(return_value, 1);
+       }
+       else {
+               ZVAL_BOOL(return_value, 0);
+       }       
+       fbcmdRelease(md);
+       if (digest_old_password) efree(digest_old_password);
+       if (digest_password) efree(digest_password);
+}
+/* }}} */
+
+
 /* {{{ proto bool fbsql_select_db([string database_name [, resource link_identifier]])
    Select the database to open */
 PHP_FUNCTION(fbsql_select_db)
index abb83049dd5e7207c33457dcfe647e93151406e3..cf3d99f1f025b04c1b835214e010911af087ddce 100644 (file)
@@ -97,6 +97,7 @@ PHP_FUNCTION(fbsql_database_password);
 PHP_FUNCTION(fbsql_username);
 PHP_FUNCTION(fbsql_password);
 PHP_FUNCTION(fbsql_warnings);
+PHP_FUNCTION(fbsql_set_password);
 
 PHP_FUNCTION(fbsql_get_autostart_info);
 /* PHP_FUNCTION(fbsql_set_autostart_info); */