Page MenuHomeIn-Portal Phabricator

in-portal
No OneTemporary

File Metadata

Created
Tue, Nov 11, 7:18 AM

in-portal

Index: branches/unlabeled/unlabeled-1.2.8/core/kernel/utility/formatters/password_formatter.php
===================================================================
--- branches/unlabeled/unlabeled-1.2.8/core/kernel/utility/formatters/password_formatter.php (nonexistent)
+++ branches/unlabeled/unlabeled-1.2.8/core/kernel/utility/formatters/password_formatter.php (revision 6435)
@@ -0,0 +1,101 @@
+<?php
+
+
+
+class kPasswordFormatter extends kFormatter
+{
+
+ function PrepareOptions($field_name, &$field_options, &$object)
+ {
+ if( isset( $field_options['verify_field'] ) )
+ {
+ $add_fields = Array();
+ $options = Array('master_field' => $field_name, 'formatter'=>'kPasswordFormatter');
+ $add_fields[ $field_options['verify_field'] ] = $options;
+
+ $add_fields[$field_name.'_plain'] = Array('type'=>'string', 'error_field'=>$field_name);
+ $add_fields[ $field_options['verify_field'].'_plain' ] = Array('type'=>'string', 'error_field'=>$field_options['verify_field'] );
+
+ $add_fields = array_merge_recursive2($add_fields, $object->VirtualFields);
+ $object->setVirtualFields($add_fields);
+ }
+ }
+
+ function Format($value, $field_name, &$object, $format=null)
+ {
+ return $value;
+ }
+
+ function Parse($value, $field_name, &$object)
+ {
+ $options = $object->GetFieldOptions($field_name);
+
+ $fields = Array('master_field','verify_field');
+ $fields_set = true;
+ $flip_count = 0;
+ while($flip_count < 2)
+ {
+ if( getArrayValue($options,$fields[0]) )
+ {
+ $object->SetDBField($field_name.'_plain', $value);
+ if( !getArrayValue($object->Fields[ $options[ $fields[0] ] ], $fields[1].'_set') )
+ {
+ $object->Fields[ $options[ $fields[0] ] ][$fields[1].'_set'] = true;
+ }
+
+ $password_field = $options[ $fields[0] ];
+ $verify_field = $field_name;
+ }
+ $fields = array_reverse($fields);
+ $flip_count++;
+ }
+
+ if( getArrayValue($object->Fields[$password_field], 'verify_field_set') && getArrayValue($object->Fields[$verify_field], 'master_field_set') )
+ {
+ $new_password = $object->GetDBField($password_field.'_plain');
+ $verify_password = $object->GetDBField($verify_field.'_plain');
+
+ if($new_password == '' && $verify_password == '')
+ {
+ if( $object->GetDBField($password_field) != $this->EncryptPassword('') )
+ {
+ if ($options['encryption_method'] == 'plain') return $value;
+ return $this->EncryptPassword($value);
+ }
+ else
+ {
+ $object->Fields[$password_field.'_plain']['required'] = true;
+ $object->Fields[$verify_field.'_plain']['required'] = true;
+ return null;
+ }
+ }
+
+ $min_length = $this->Application->ConfigValue('Min_Password');
+ if( strlen($new_password) >= $min_length )
+ {
+ if($new_password != $verify_password)
+ {
+ $object->ErrorMsgs['passwords_do_not_match'] = $this->Application->Phrase('lu_passwords_do_not_match');
+ $object->FieldErrors[$password_field]['pseudo'] = 'passwords_do_not_match';
+ $object->FieldErrors[$verify_field]['pseudo'] = 'passwords_do_not_match';
+ }
+ }
+ else
+ {
+ $object->ErrorMsgs['passwords_min_length'] = sprintf($this->Application->Phrase('lu_passwords_too_short'), $min_length);
+ $object->FieldErrors[$password_field]['pseudo'] = 'passwords_min_length';
+ $object->FieldErrors[$verify_field]['pseudo'] = 'passwords_min_length';
+ }
+ }
+ if($value == '') return $object->GetDBField($field_name);
+
+ if ($options['encryption_method'] == 'plain') return $value;
+ return $this->EncryptPassword($value);
+ }
+
+ function EncryptPassword($value, $salt=null)
+ {
+ if (!isset($salt)) return md5($value);
+ return md5(md5($value).$salt);
+ }
+}
\ No newline at end of file
Property changes on: branches/unlabeled/unlabeled-1.2.8/core/kernel/utility/formatters/password_formatter.php
___________________________________________________________________
Added: cvs2svn:cvs-rev
## -0,0 +1 ##
+1.2
\ No newline at end of property
Added: svn:executable
## -0,0 +1 ##
+*
\ No newline at end of property

Event Timeline