Encrypting Passwords in PHP

AmitDiwan
Updated on 07-Apr-2020 12:10:49

321 Views

Due to the fact that Blowfish has vulnerabilities before PHP version 5.3.7, it would be suggested to use SHA-256 or SHA-512 instead. Both of them have a similar salt format similar to that of Blowfish (use a prefix of $5$ for SHA-256 and $6$ for SHA-512). In addition to this, it also contains an optional rounds parameter to force multiple hashing.The salt on its own is a little shorter at only 16 characters but unlike Blowfish, it allows more than just alphanumeric characters.Example Live Demoecho 'SHA-256 (no rounds): ' . crypt('password-to-encrypt', '$5$YourSaltyStringz$'); echo 'SHA-512 (with rounds): ' . crypt('password-to-encrypt', '$6$rounds=1000$YourSaltyStringz$');OutputThis will ... Read More

Check PowerShell Version Installed on Local and Remote Systems

Chirag Nagrekar
Updated on 07-Apr-2020 11:58:36

2K+ Views

To check the PowerShell version installed in your system, you can use either $PSVersionTable or $host command.Check if $host command available in remote servers.Open the PowerShell console in the system and run the command $PSVersionTable.$PSVersionTableOutputPS C:\WINDOWS\system32> $PSVersionTable Name                           Value ----                             ----- PSVersion                        5.1.18362.628 PSEdition                        Desktop PSCompatibleVersions       ... Read More

Checking Memory Limit in PHP

AmitDiwan
Updated on 07-Apr-2020 11:58:33

1K+ Views

The ‘memory_limit’ is the maximum amount of server memory that a single PHP script is allowed to use. The value needs to be converted before comparing the threshold of memory.For example − 64M is converted to 64 * 1024 * 1024. After this, the comparison is done and the result is printed out.

Difference Between isset and empty in PHP

AmitDiwan
Updated on 07-Apr-2020 11:56:02

969 Views

Isset functionISSET checks the variable to see if it has been set. In other words, it checks to see if the variable is any value except NULL or not assigned a value. ISSET returns TRUE if the variable exists and has a value other than NULL. That means variables assigned a "", 0, "0", or FALSE are set, and therefore are TRUE for ISSET.Example Live DemoOutputThis will produce the following output −0 is set with isset function array is not set.!empty functionEMPTY checks to see if a variable is empty. Empty is interpreted as: "" (an empty string), 0 (integer), 0.0 ... Read More

Remove Numbers After Hyphen in Varchar String with MySQL Query

AmitDiwan
Updated on 07-Apr-2020 11:54:11

591 Views

For this, use SUBSTRING_INDEX(). Let us first create a table −mysql> create table DemoTable2040    -> (    -> StudentCode varchar(20)    -> ); Query OK, 0 rows affected (0.85 sec)Insert some records in the table using insert command −mysql> insert into DemoTable2040 values('John-232'); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable2040 values('Carol-901'); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable2040 values('David-987'); Query OK, 1 row affected (0.21 sec)Display all records from the table using select statement −mysql> select *from DemoTable2040;This will produce the following output −+-------------+ | StudentCode | +-------------+ | ... Read More

Detect Client Locale in PHP

AmitDiwan
Updated on 07-Apr-2020 11:52:30

1K+ Views

PHP provides a function beginning from 5.3.0 to parse the ‘$_SERVER['HTTP_ACCEPT_LANGUAGE']’ variable into a locale −Example$locale = Locale::acceptFromHttp($_SERVER['HTTP_ACCEPT_LANGUAGE']); echo $locale;The ‘$_SERVER['HTTP_ACCEPT_LANGUAGE']’ function helps detect the locale by taking the current locale’s language as the parameter.OutputThis will produce the following output −en_USMost browsers submit an Accept-Language HTTP header that specifies en-us if they are from the US. Some older browsers use en only.English-UK based users usually set their system or user locale to English-UK, which is the default browser configuration. This would result in en-gb as the Accept Language header. Other countries have en locales, such as en-za (South Africa), and ... Read More

Display Records in Ascending Order with MySQL

AmitDiwan
Updated on 07-Apr-2020 11:52:28

176 Views

To display a list of records in a specific order, you need to set conditions and use ORDER BY. For this, use ORDER BY CASE statement. Let us first create a table −mysql> create table DemoTable2039    -> (    -> Name varchar(20)    -> ); Query OK, 0 rows affected (0.62 sec)Insert some records in the table using insert command −mysql> insert into DemoTable2039 values('John Doe'); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable2039 values('John Smith'); Query OK, 1 row affected (0.08 sec) mysql> insert into DemoTable2039 values('Chris Brown'); Query OK, 1 row affected ... Read More

MySQL Query to Return True for Rows Having Positive Value

AmitDiwan
Updated on 07-Apr-2020 11:51:39

294 Views

To return TRUE for positive values and FALSE for negative, use MySQL IF(). Let us first create a table −mysql> create table DemoTable2038    -> (    -> Id int NOT NULL AUTO_INCREMENT PRIMARY KEY,    -> Value int    -> ); Query OK, 0 rows affected (0.87 sec)Insert some records in the table using insert command −mysql> insert into DemoTable2038(Value) values(57); Query OK, 1 row affected (0.18 sec) mysql> insert into DemoTable2038(Value) values(-100);; Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable2038(Value) values(-78); Query OK, 1 row affected (0.42 sec) mysql> insert into DemoTable2038(Value) ... Read More

Reading and Writing a MS Word File in PHP

AmitDiwan
Updated on 07-Apr-2020 11:50:09

690 Views

Microsoft strongly advises not to use the automation of Office documents via COM objects. It quotes the following −“Microsoft does not currently recommend or support the Automation of Microsoft Office applications from any unattended, non-interactive client application or component (including ASP, ASP.NET, DCOM, and NT Services), because Office may exhibit unstable behavior and/or deadlock when Office is run in this environment.”A .docx file can be created without COM objects since it has XML foundations (PHPDOCX could be used for this). An added advantage of this method is that a local copy of Word that was installed wouldn’t have to be created ... Read More

Recreate and Display an Image from Binary Data in PHP

AmitDiwan
Updated on 07-Apr-2020 11:48:20

2K+ Views

This can be done using data URI in the image src attribute.Formatdata:[][;charset=""][;base64],

Advertisements