Sep 042012
 

MySQL에서 사용하는 패스워드로 사용할 수 있는 함수를 버전별로 테스트한 결과입니다.

프로그램을 시작할때 참고를 해서 테스트를 해보시면 좋습니다.

비밀번호를 md5()를 한 다음에 sha1()을 처리하고, 나머지 데이타는 encode() 혹은 des_encrypt()를 내부 암호키를 이용해서 저장하고 관리하는 방법을 사용하면 효과적입니다.

[smlee@A ~]$ mysql -p -u root
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 644167
Server version: 5.0.77 Source distribution

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql> select password('dltjrans');
+----------------------+
| password('dltjrans') |
+----------------------+
| 337c52a05f635196     |
+----------------------+
1 row in set (0.03 sec)

mysql> select sha1('dltjrans');
+------------------------------------------+
| sha1('dltjrans')                         |
+------------------------------------------+
| 2734580af3645aae53a80ce3a60841636e4f5f16 |
+------------------------------------------+
1 row in set (0.02 sec)

mysql> select sha2('dltjrans');
ERROR 1305 (42000): FUNCTION sha2 does not exist

mysql> select encrypt('dltjrans');
+---------------------+
| encrypt('dltjrans') |
+---------------------+
| iBlePNVyWUPF2       |
+---------------------+
1 row in set (0.00 sec)

mysql> select md5('dltjrans');
+----------------------------------+
| md5('dltjrans')                  |
+----------------------------------+
| 44022b75cd0626a239a1c0ec42e0b902 |
+----------------------------------+
1 row in set (0.00 sec)

mysql> select old_password('dltjrans');
+--------------------------+
| old_password('dltjrans') |
+--------------------------+
| 337c52a05f635196         |
+--------------------------+
1 row in set (0.00 sec)

mysql> show variables;
+---------------------------------+------------------------------------------------------------+
| Variable_name                   | Value                                                      |
+---------------------------------+------------------------------------------------------------+
......
| old_passwords                   | ON                                                         |
......
+---------------------------------+------------------------------------------------------------+
239 rows in set (0.01 sec)

[smlee@B ~]$ /usr/local/mysql/bin/mysql --character-sets-dir=utf8  -p -u root
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 326943
Server version: 5.1.58-log Source distribution

Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
This software comes with ABSOLUTELY NO WARRANTY. This is free software,
and you are welcome to modify and redistribute it under the GPL v2 license

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> select password('dltjrans');
+-------------------------------------------+
| password('dltjrans')                      |
+-------------------------------------------+
| *8FE4DE9DB3E99B3D33C46101724499112B4E08C0 |
+-------------------------------------------+
1 row in set (0.00 sec)

mysql> select sha('dltjrans');
+------------------------------------------+
| sha('dltjrans')                          |
+------------------------------------------+
| 2734580af3645aae53a80ce3a60841636e4f5f16 |
+------------------------------------------+
1 row in set (0.00 sec)

mysql> select sha1('dltjrans');
+------------------------------------------+
| sha1('dltjrans')                         |
+------------------------------------------+
| 2734580af3645aae53a80ce3a60841636e4f5f16 |
+------------------------------------------+
1 row in set (0.00 sec)

mysql> select encrypt('dltjrans');
+---------------------+
| encrypt('dltjrans') |
+---------------------+
| dZew2kBw.Cajg       |
+---------------------+
1 row in set (0.00 sec)

mysql> select old_password('dltjrans');
+--------------------------+
| old_password('dltjrans') |
+--------------------------+
| 337c52a05f635196         |
+--------------------------+
1 row in set (0.00 sec)

[smlee@C ~]$ mysql -p -u root
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 33751
Server version: 5.5.21 MySQL Community Server (GPL)

Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> select password('dltjrans');
+-------------------------------------------+
| password('dltjrans')                      |
+-------------------------------------------+
| *8FE4DE9DB3E99B3D33C46101724499112B4E08C0 |
+-------------------------------------------+
1 row in set (0.00 sec)

mysql> select sha('dltjrans');
+------------------------------------------+
| sha('dltjrans')                          |
+------------------------------------------+
| 2734580af3645aae53a80ce3a60841636e4f5f16 |
+------------------------------------------+
1 row in set (0.03 sec)

mysql> select sha1('dltjrans');
+------------------------------------------+
| sha1('dltjrans')                         |
+------------------------------------------+
| 2734580af3645aae53a80ce3a60841636e4f5f16 |
+------------------------------------------+
1 row in set (0.00 sec)

mysql> select encrypt('dltjrans');
+---------------------+
| encrypt('dltjrans') |
+---------------------+
| yb/DPswDxmSnk       |
+---------------------+
1 row in set (0.00 sec)

mysql> select old_password('dltjrans');
+--------------------------+
| old_password('dltjrans') |
+--------------------------+
| 337c52a05f635196         |
+--------------------------+
1 row in set (0.00 sec)

mysql>
Sep 042012
 

DB에서 가능하면 join을 사용하지 않도록 설계를 하면 성능에 많은 도움이 된다.

하지만 어쩔수 없는 경우에는 outer join을 사용하면 빠른 속도로 join이 가능하다.

그래서 left outer join을 자주 사용하게 되는데. 이런 경우 join이 되는 테이블의 데이타가 없는 경우에도 결과값은 생성이 되게 된다.

이런 경우에 join이 되는 테이블의 데이타가 없는 경우에는 아래와 같이 판별이 가능한다.
(MySQL 메뉴얼에서 참고한 내용)

If there is a row in A that matches the WHERE clause, but there is no row in B that matches the ON condition, an extra B row is generated with all columns set to NULL.

실제로 2개의 테이블이 느슨한 연결 상태라서 foreign key가 없는 row가 존재할 수 있다.
아래와 같은 쿼리를 통해서 확인하고, delete 처리가 가능하다.

SELECT *
FROM tb_abc a
LEFT JOIN tb_123 b ON a.title = b.title
WHERE a.TYPE = 'ok'
AND b.STATUS IS NULL

참고 URL : http://dev.mysql.com/doc/refman/5.5/en/left-join-optimization.html

Sep 042012
 

php에서 time() 을 호출하게 되면 unix timestamp를 반환하게 된다. 해당 값은 단위가 초이기 때문에 간단한 수칙연산으로 날짜를 변경이 가능하다.

하지만, 현재 시간에서 1달을 더하거나 할때에는 생각할 부분이 많다. 30 혹은 31일인 경우까지 고려를 해야 하며, 1년을 더 할 경우에는 윤년 계산까지 해야 한다.

이럴때 아래의 strtotime() 를 사용하면 보다 간편하게 계산이 가능하다.

 
<?php
echo strtotime("now"), "\n";
echo strtotime("10 September 2000"), "\n";
echo strtotime("+1 day"), "\n";
echo strtotime("+1 week"), "\n";
echo strtotime("+1 week 2 days 4 hours 2 seconds"), "\n";
echo strtotime("next Thursday"), "\n";
echo strtotime("last Monday"), "\n";
?>

참고 URL: http://www.php.net/manual/en/function.strtotime.php
참고 URL: http://www.php.net/manual/en/function.time.php

Plugin from the creators of Brindes :: More at Plulz Wordpress Plugins