php date time supporting date values before year 1970

“I need to store birthdate of my customers where it can fall before year 1970.” Php function date(), strtotime() uses UNIX timestamp which supports year 1970 to 2038. To work with date values beyond that, we need to use php datetime class which is available on after php version 5.2.0 (datetime manual). Create a date before 1970: $dt = new DateTime(); $dt->setDate(1945, 8, 8); // August 8 1945, end of world war 2 If you need to store time as well: //public DateTime DateTime::setTime ( int $hour , int $minute [, int $second = 0 ] ) //seconds argument is optional $dt->setTime(8,0,45); // 8:00:45 am To print the date: echo¬†$dt->format('Y-m-d H:i:s'); //outputs //1945-08-08 08:00:45 For list of date format to use, refer to http://php.net/manual/en/function.date.php. Hope it helps....

Apache web server – password protect your website / directory

You are developing a new site and wish to keep it secret till your new site is ready for launch? You got personal photos, confidential documents, project codes uploaded to your web server for future reference or download and you want to give access only to certain people? One of the solutions is to password protect your directory where the restricted stuffs were stored. “How to password protect the directory or entire website?” Requirements: – Hosted on apache server – Apache module mod_access is enabled. Step 1 Create password file “.htpasswd”. In the folder / site root you wish to password protect, create a .htpasswd file. The password file stores your valid users’ username and password. Step 2 Use online passwd generator to create user’s username and password entry for htpasswd. http://www.htaccesstools.com/htpasswd-generator/ Copy and paste the entries into “.htpasswd”. Example of an .htpasswd file denny:$apr1$7APPNnCz$M./pcs91u296uBP0VAD4J1 Step 3 In the same folder, create/edit .htaccess to include the following codes. AuthUserFile /absolute/path/to/.htpasswd AuthType Basic AuthName "Prompt Title" Require valid-user Note: Relative path to .htpasswd will not work. Final Step Launch your browser, navigate to the password protected folder, you will receive a authentication challenge if nothing goes wrong. =D That’s...

.net csharp store password as md5 hash into mssql database

Storing plain-text password into database is completely insecure and not recommended. Several methods to store encrypted password such as using LDAP server or hashing the password before saving to database. Below is an example how to hash the password using MD5 before writing to database and authenticate user. //In order to use MD5 class, we need to import System.Security.Cryptography; using System.Security.Cryptography; //MD5 Hashstring static method public static string MD5HashString(string input) { MD5 md5Hash = MD5.Create(); // Convert the input string to a byte array and compute the hash. byte[] data = md5Hash.ComputeHash(Encoding.UTF8.GetBytes(input)); // Create a new Stringbuilder to collect the bytes // and create a string. StringBuilder sBuilder = new StringBuilder(); // Loop through each byte of the hashed data // and format each one as a hexadecimal string. for (int i = 0; i < data.Length; i++) { sBuilder.Append(data[i].ToString("x2")); } // Return the hexadecimal string. return sBuilder.ToString(); } //Create user login method public bool createUserAccount(string strUsername, string strPassword) { //validation //check if username is valid if(!UserEntity.isValidUsername(strUsername)){ //username invalid return false; } //check if password is valid if(!UserEntity.isValidPassword(strPassword)){ //password entered fail password policy validation return false; } //all validation passed //md5 hash user password string hashUserPassword = common.CommonFunction.MD5HashString(strPassword); //initialize data access layer object UserDA objUserDa = new UserDA(); //write to database bool insertResult = objUserDa.createNewUser(strUsername, hashUserPassword); return insertResult; } //Authenticate user public bool userLogin(string strUsername, string strPassword) { //check whether user login valid UserDA objUserDa = new UserDA(); //retrieve user id by username int userId = objUserDa.getUseridByUsername(strUsername); if(userId == -1) { //user records not found return false; } //convert user password to md5 string md5password = common.CommonFunction.MD5HashString(strPassword); //retrieve user...