Quick Password Policy Function in PHP

PHP, Security 1 Comment »

Just a quick password policy function in php. Didn’t want to have to dig around to figure out how to do it again, so I’m just posting it here

/* * * * * * * * * * * * * * * * * * * * * * * * *
Password Policy requires
– at least 8 characters
– at least 1 lower case
– at least 1 upper case
– at least 1 digit
* * * * * * * * * * * * * * * * * * * * * * * * * /
function pwdPolicy($pwd){
   $policy = “/^.*(?=.{8,})(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).*$/”;
   if(preg_match($policy, $pwd, $matches)){
      return true;
   } else return false;
}

PHP/MySQL on the Mac

Mac, MySQL, PHP No Comments »

First Enable Apache:

  • System Preferences > Sharing
  • Check ‘Personal Web Sharing’

Then edit httpd.conf

  • sudo vi /etc/httpd/httpd.conf
  • locate these lines and remove the hashes in front:

#LoadModule php4_module
#AddModule mod_php4.c
#AddType application/x-httpd-php .php
#AddType application/x-httpd-php-source .phps

Download and install MySQL for the Mac (10.3, 10.4, etc)

  • http://dev.mysql.com/downloads/mysql/5.0.html
  • Type this into the terminal:

$ sudo ln -s /usr/local/mysql/bin/mysql /usr/local/bin/mysql
$ mysql -u root mysql

  • Then set a password (changing “NewPw”, of course):

> update user set Password=password('NewPw‘) where User=’root’;
> flush privileges;

How to fix Warning: mysql_connect(): Can’t connect to local MySQL server through socket ‘/var/mysql/mysql.sock’
Apparently, OS X Tiger doesn’t allow for PHP MySQL connection out of the box. You get this: Warning: mysql_connect(): Can’t connect to local MySQL server through socket ‘/var/mysql/mysql.sock’
/etc/php.ini(.default) looks for mysql.sock in the wrong place… two options are to make a symbolic link from the right place to the socket…

$ sudo mkdir /var/mysql
$ sudo ln -s /private/tmp/mysql.sock /var/mysql/mysql.sock

Or you can update your php.ini (.default) by finding “mysql.default_socket” and setting it to equal /private/tmp/mysql.sock and then restart apache with “apachectl graceful