For administrator from customer shepi75

Talk about Password fields

Moderator: alexandrleonenko

shepi75
Newbie
Newbie
Posts: 6
Joined: Oct 18th, '10, 11:04

For administrator from customer shepi75

Postby shepi75 » Oct 20th, '10, 12:33

Dear Admin

I whant to make update password field in tbl mysql witch encrypt aes. I have 2 formulars create_user.php and change_user.php.
Create_user.php create record in to table authorized_user and encrypt password to aes. Change_user.php is Datagrid for editing values from tbl authorized_user. And here I have problem with update field password in tbl. I whant change old value password on new value password but with encrypt AES. This time the new value for field password is not encrypt .
Create_user.php

Code: Select all

<?php include('inc/start_page.php');?>
<?php include('do_header.php'); ?>


<?php
    $mode = isset($_POST['abc_mode']) ? $_POST['abc_mode'] : "";


      define ("DATAFORM_DIR", "../DASK_FRM/");                     /* Ex.: "dataform/" */
      define ("PEAR_DIR", "../DASK_FRM/pear/");                    /* Ex.: "dataform/pear/" */

      require_once(DATAFORM_DIR.'dataform.class.php');
      require_once(PEAR_DIR.'PEAR.php');
      require_once(PEAR_DIR.'DB.php');

      include_once('../DASK_FRM/examples/install/config.inc.php');
      $DB_HOST='localhost';
      $DB_NAME='DASK_ADM';
      $DB_USER='root';
      $DB_PASS='hokej';

      ob_start();
    
     $db_conn = DB::factory('mysql');
      $result_conn = $db_conn->connect(DB::parseDSN('mysql://'.$DB_USER.':'.$DB_PASS.'@'.$DB_HOST.'/'.$DB_NAME));
      if(DB::isError($result_conn)){ die($result_conn->getDebugInfo()); } 

      $debug_mode = false;
      $messaging = true;
      $unique_prefix = "";
      $dform = new DataForm($debug_mode, $messaging, $unique_prefix, DATAFORM_DIR);

    $dform->DataSource($db_conn);      
 
    $df_language = "cz"; 
    $dform->SetInterfaceLang($df_language);
    ##  *** set modes
     $modes = array(
         "add" =>true,
         "insert" =>true,
         "preview" =>true,
         "edit" =>true
     );
     $dform->SetModes($modes);
   
    ##  *** define mode after successful insertion
     $df_mode_after_insert = "add";
     $dform->SetModeAfterInsert($df_mode_after_insert);

     $css_class = "x-blue";
     $dform->SetCssClass($css_class);
    ##  *** set variables that used to get access to the page (like: my_page.php?act=34&id=56 etc.)
    /// $http_get_vars = array("act", "id");
    /// $dform->SetHttpGetVars($http_get_vars);
    ##  *** set DataForm cancel link (ex.: http://domain.com/index.php)
    /// $df_cancel_link = "";
    /// $dform->SetCancelLink($df_cancel_link);
    ##  *** set DataForm result HTML
     $df_result_html = "Nový uživateľ bol vytvorený!";
     $dform->SetResultHtml($df_result_html);
    ##  *** set DataForm caption
     $df_caption = "Vytvorenie uživateľa(<a href='../index.php'>Späť</a>)";
     $dform->SetCaption($df_caption);

    ##
    ## +---------------------------------------------------------------------------+
    ## | 3. Mode Settings:                                                         |
    ## +---------------------------------------------------------------------------+
    ##  *** set mode table properties
     $am_table_properties = array("width"=>"510px");
     $dform->SetAddModeTableProperties($am_table_properties);
    ##  *** set preview mode table properties
     $pm_table_properties = array("width"=>"500px");
     $dform->SetPreviewModeTableProperties($pm_table_properties);
    ##  ***  set settings for add/edit/details modes
      $table_name  = "authorized_users";
      $primary_key = "id";
    ##  for ex.: "table_name.field = ".$_REQUEST['abc_rid'];
      $condition   = "";
      $dform->SetTable($table_name, $primary_key, $condition);
    ##  *** set columns in edit mode   
    ##  *** first letter:  r - required, s - simple (not required)
    ##  *** second letter: t - text(including datetime), n - numeric, a - alphanumeric,
    ##                     e - email, f - float, y - any, l - login name, z - zipcode,
    ##                     p - password, i - integer, v - verified, c - checkbox, u - URL
    ##  *** third letter (optional):
    ##          for numbers: s - signed, u - unsigned, p - positive, n - negative
    ##          for strings: u - upper,  l - lower,    n - normal,   y - any
    ##  *** Ex.: "on_js_event"=>"onclick='alert(\"Yes!!!\");'"
    ##  *** Ex.: type = textbox|textarea|label|date(yyyy-mm-dd)|datedmy(dd-mm-yyyy)|datetime(yyyy-mm-dd hh:mm:ss)|datetimedmy(dd-mm-yyyy hh:mm:ss)|time(hh:mm:ss)|image|password|enum|print|checkbox
    ##  *** make sure your WYSIWYG dir has 755 access permissions
    ##  *** make sure uploading directories for files/images have 755 access permissions
    /// $fill_from_array = array("0"=>"No", "1"=>"Yes", "2"=>"Don't know", "3"=>"My be"); /* as "value"=>"option" */
   
     $am_columns = array(

        "delimiter_1"    =>array("inner_html"=>"<br /><font style='font-size:16px;font-weight:bold;color:#336699'> <i>DASK:</i></font><br /><hr style='color:#336699'>"),   
       
      "name"           =>array("header"=>"Uživateľske meno", "type"=>"textbox",    "req_type"=>"rt", "width"=>"210px", "title"=>"", "readonly"=>"false", "maxlength"=>"-1", "default"=>"", "unique"=>true, "unique_condition"=>"", "visible"=>"true", "on_js_event"=>""),
      
        "password"    =>array("header"=>"Uživateľske heslo", "type"=>"password","req_type"=>"rt", "width"=>"210px", "title"=>"", "readonly"=>"false", "default"=>"", "unique"=>"false", "unique_condition"=>"", "visible"=>"true", "hide"=>"false", "cryptography"=>"true", "cryptography_type"=>"aes", "aes_password"=>"xxx","validation_type"=>"password"),
      
      "level_id"    =>array("header"=>"Typ konta", "type"=>"foreign_key","req_type"=>"ri", "width"=>"210px", "title"=>"", "readonly"=>"false", "default"=>"", "unique"=>"false", "unique_condition"=>"", "visible"=>"true"),

        "delimiter_2"    =>array("inner_html"=>"<br /><font style='font-size:16px;font-weight:bold;color:#336699'> <i></i></font><br /><hr style='color:#336699'>"),   
       
     );
     
     $dform->SetColumns($am_columns);
    ##  *** set auto-generated columns in edit mode
    //  $auto_column_in_edit_mode = false;
    //  $dform->SetAutoColumnsInAddMode($auto_column_in_edit_mode);
    ##  *** set foreign keys for add/edit/details modes (if there are linked tables)
    ##  *** Ex.: "field_name"=>"CONCAT(field1,','field2) as field3"
    ##  *** Ex.: "condition"=>"TableName_1.FieldName > 'a' AND TableName_1.FieldName < 'c'"
    ##  *** Ex.: "on_js_event"=>"onclick='alert(\"Yes!!!\");'"
     $foreign_keys = array(
        "level_id"=>array("table"=>"level_users", "field_key"=>"level_id", "field_name"=>"account", "view_type"=>"dropdownlist","condition"=>"", "order_by_field"=>"level_id", "order_type"=>"ASC", "on_js_event"=>""),
     );
   
     $dform->SetForeignKeysAdd($foreign_keys);

    ## +---------------------------------------------------------------------------+
    ## | 8. Bind the DataForm:                                                     |
    ## +---------------------------------------------------------------------------+
    ##  *** bind the DataForm and draw it on the screen
      $dform->Bind();
   ob_end_flush();   
     ###############################################################################   

?>
<?php include('do_footer.php'); ?>



Change_user.php

Code: Select all

<?php include('inc/start_page.php');?>
<?php include('do_header.php'); ?>


<?php

      define ("DATAGRID_DIR", "../DASK_GRD/");
      define ("PEAR_DIR", "../DASK_GRD/pear/");
   
      require_once(DATAGRID_DIR.'datagrid.class.php');
      require_once(PEAR_DIR.'PEAR.php');
      require_once(PEAR_DIR.'DB.php');
   

      include_once('../DASK_GRD/examples/install/config.inc.php');
     
      $DB_USER='root';
      $DB_PASS='hokej';
      $DB_HOST='localhost';
      $DB_NAME='DASK_ADM';
   
    ob_start();
      $db_conn = DB::factory('mysql');
      $result_conn = $db_conn->connect(DB::parseDSN('mysql://'.$DB_USER.':'.$DB_PASS.'@'.$DB_HOST.'/'.$DB_NAME));
      if(DB::isError($result_conn)){ die($result_conn->getDebugInfo()); }
     
      $sql=" SELECT authorized_users.id,
     authorized_users.name,
     AES_DECRYPT(authorized_users.password,'xxx')as password,
     level_users.account FROM authorized_users
     LEFT OUTER JOIN
     level_users ON authorized_users.level_id = level_users.level_id";
       
      $debug_mode = true;
      $messaging = true;
      $unique_prefix = "";
    
      
      $dgrid = new DataGrid($debug_mode, $messaging, $unique_prefix, DATAGRID_DIR);
     //nastavujem co sa ma zobrazir pre editaciu udajov
     $modes = array(
"add"     =>array("view"=>false, "edit"=>false, "type"=>"link",
"show_add_button"=>"inside|outside"),

"edit"     =>array("view"=>true, "edit"=>true,"type"=>"link", "byFieldValue"=>""),

"cancel"  =>array("view"=>true, "edit"=>true,  "type"=>"link"),

"details" =>array("view"=>true, "edit"=>true, "type"=>"link"),

"delete"  =>array("view"=>true, "edit"=>true,  "type"=>"image")
);
$dgrid->SetModes($modes);
   //nastavujem co sa ma zobrazir pre editaciu udajov

    $dg_encoding = "utf8";
     $dg_collation = "utf8_unicode_ci";
     $dgrid->SetEncoding($dg_encoding, $dg_collation);
    $dg_language = "cz";
    $dgrid->SetInterfaceLang($dg_language); 
    ##  *** set data source with needed options
      $default_order_field = "level_users.account";
      $default_order_type = "ASC";
      $dgrid->DataSource($db_conn, $sql, $default_order_field, $default_order_type);      
      $dg_caption = '<b>Create/Change user</b> - <a href=../index.php>Back</a>';
      $dgrid->SetCaption($dg_caption);
   
      ///ked chcem automaticke generovanie poli////
      //////$dgrid->SetAutoColumnsInViewMode(true);
    
     ///popis a obsah poli
     $dg_columns = array(
        "name"       =>array("header"=>"Meno","type"=>"label","align"=>"left","wrap"=>"wrap","text_length"=>"20", "case"=>"normal"),
      
      "password"   =>array("header"=>"Heslo", "type"=>"password", "req_type"=>"rp", "width"=>"210px", "title"=>"", "readonly"=>"false", "default"=>"", "unique"=>"false", "unique_condition"=>"", "visible"=>"true", "on_js_event"=>"", "hide"=>"false", "generate"=>"true", "cryptography"=>"true", "cryptography_type"=>"aes", "aes_password"=>"xxx","validation_type"=>"password"),
     );
     
     $dgrid->SetColumnsInViewMode($dg_columns);
      
      $table_name = "authorized_users";
      $primary_key = "id";
      $condition = "";
      $dgrid->SetTableEdit($table_name, $primary_key, $condition);

     $dgrid->SetAutoColumnsInEditMode($dg_columns);
     
     $css_class = "x-blue";
      $dgrid->SetCssClass($css_class);

        $dgrid->Bind();       
      ob_end_flush();
    ################################################################################   

?>
<?php include('do_footer.php'); ?>


result from change_user.php

Code: Select all

Retrieve data for current mode:
select sql (celkem: 2) SELECT authorized_users.id, authorized_users.name, AES_DECRYPT(authorized_users.password,'xxx')as password, level_users.account FROM authorized_users LEFT OUTER JOIN level_users ON authorized_users.level_id = level_users.level_id WHERE 1=1 ORDER BY level_users.account ASC LIMIT 0, 10
Updating requested record:
update sql #8 (celkem: 1) UPDATE authorized_users SET level_id = '1' , name = 'test' , password = 'test' , date = '2010-10-20 13:19:24' WHERE id = '8'
Retrieve data for current mode:
select sql (celkem: 2) SELECT authorized_users.id, authorized_users.name, AES_DECRYPT(authorized_users.password,'xxx')as password, level_users.account FROM authorized_users LEFT OUTER JOIN level_users ON authorized_users.level_id = level_users.level_id WHERE 1=1 ORDER BY level_users.account ASC LIMIT 0, 10
 
POST: Array ( [_operation_randomize_code] => l3bhtn224sqa943kpnbo [siylevel_id] => 1 [rtyname] => test [stypassword] => test [stydate] => 2010-10-20 13:19:24 )

GET: Array ( [mode] => update [rid] => 8 [page_size] => 10 [p] => 1 )
 


administrator
Site Admin
Site Admin
Posts: 6074
Joined: Jan 7th, '09, 23:18
Contact:

Re: For administrator from customer shepi75

Postby administrator » Oct 21st, '10, 09:06

1. Check does your password values really inserted in database table already encoded.

2. $dgrid->SetAutoColumnsInEditMode($dg_columns); - datagrid cannot recognize password fields if you didn't specify it directly.

3. The right syntax for datagrid password fields is:

"name" =>array("header"=>"Name_H", "type"=>"password", "req_type"=>"rp", "width"=>"210px", "title"=>"", "readonly"=>"false", "maxlength"=>"-1", "default"=>"", "unique"=>"false", "unique_condition"=>"", "visible"=>"true", "on_js_event"=>"", "hide"=>"false", "generate"=>"true", "cryptography"=>"true", "cryptography_type"=>"aes", "aes_password"=>"xxx"),

shepi75
Newbie
Newbie
Posts: 6
Joined: Oct 18th, '10, 11:04

Re: For administrator from customer shepi75 passwd is OK

Postby shepi75 » Oct 21st, '10, 12:14

Oh my god I am idiot :oops:
I understand where was error. Your typ was excelent right. For all , dont use SetAutoColumnsInEditMode but SetColumnsInEditMode (your create manual columns) !!!

thank you Admin i going to write next pages


Return to “Field type: "password"”