Flicker Images

Find programmers and grapic design experts at ScriptLance.com

Wednesday, November 13, 2013

Generating a random password in php


I am trying to generate a random password in php.
I found couple of solution for this .

solution 01
use strlen instead of count, because count on a string is always 1
 
<?php
function randomPassword() {
    $alphabet = "abcdefghijklmnopqrstuwxyzABCDEFGHIJKLMNOPQRSTUWXYZ0123456789";
    $pass = array(); //remember to declare $pass as an array
    $alphaLength = strlen($alphabet) - 1; //put the length -1 in cache
    for ($i = 0; $i < 8; $i++) {
        $n = rand(0, $alphaLength);
        $pass[] = $alphabet[$n];
    }
    return implode($pass); //turn the array into a string
}
echo randomPassword();?>

Solution 02
<?php

  function generatePassword ($length = 8)
  {

    // start with a blank password
    $password = "";

    // define possible characters - any character in this string can be
    // picked for use in the password, so if you want to put vowels back in
    // or add special characters such as exclamation marks, this is where
    // you should do it
    $possible = "2346789bcdfghjkmnpqrtvwxyzBCDFGHJKLMNPQRTVWXYZ";

    // we refer to the length of $possible a few times, so let's grab it now
    $maxlength = strlen($possible);
  
    // check for length overflow and truncate if necessary
    if ($length > $maxlength) {
      $length = $maxlength;
    }
	
    // set up a counter for how many characters are in the password so far
    $i = 0; 
    
    // add random characters to $password until $length is reached
    while ($i < $length) { 

      // pick a random character from the possible ones
      $char = substr($possible, mt_rand(0, $maxlength-1), 1);
        
      // have we already used this character in $password?
      if (!strstr($password, $char)) { 
        // no, so it's OK to add it onto the end of whatever we've already got...
        $password .= $char;
        // ... and increase the counter by one
        $i++;
      }

    }

    // done!
    return $password;

  }

?>

solution 03


<?php
 
function generatePassword($length=9, $strength=0) {
    $vowels = 'aeuy';
    $consonants = 'bdghjmnpqrstvz';
    if ($strength & 1) {
        $consonants .= 'BDGHJLMNPQRSTVWXZ';
    }
    if ($strength & 2) {
        $vowels .= "AEUY";
    }
    if ($strength & 4) {
        $consonants .= '23456789';
    }
    if ($strength & 8) {
        $consonants .= '@#$%';
    }
 
    $password = '';
    $alt = time() % 2;
    for ($i = 0; $i < $length; $i++) {
        if ($alt == 1) {
            $password .= $consonants[(rand() % strlen($consonants))];
            $alt = 0;
        } else {
            $password .= $vowels[(rand() % strlen($vowels))];
            $alt = 1;
        }
    }
    return $password;
}
 
?>
Share:

Monday, July 15, 2013

Rename a Database and its MDF and LDF files in SQL Server

In Developing a solution or rebuild a solution some time we need to change database rename and it's data file. I found couple of solution in online . I am prefer to use T-SQL .
 
USE [master]
--Set Database to Single-User Mode
ALTER DATABASE [OLD_DB] SET  SINGLE_USER WITH ROLLBACK IMMEDIATE

--Rename Database
ALTER DATABASE [OLD_DB] MODIFY Name = [NEW_DB]

--Set Database to Multi-User Mode
ALTER DATABASE [CSLMS] SET  MULTI_USER WITH ROLLBACK IMMEDIATE




--Rename Logical File Names
ALTER DATABASE [NEW_DB]
            MODIFY FILE (NAME=N'OLD_DB', NEWNAME=N'NEW_DB')
ALTER DATABASE [NEW_DB]
            MODIFY FILE (NAME=N'OLD_DB_log', NEWNAME=N'NEW_DB_log')


-- Checking Physical name
SELECT      name, physical_name
FROM        [CSLMS].sys.database_files


-- Detach Database
USE [master]
ALTER DATABASE [NEW_DB]
SET SINGLE_USER WITH ROLLBACK IMMEDIATE

EXEC master.dbo.sp_detach_db @dbname = N'CSLMS'
  
Now we rename the database physical files using Windows Explorer;
 
--Attach Database
USE [master]
CREATE DATABASE [NEW_DB] ON
( FILENAME = N'C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\DATA\NEW_DB.mdf'),
( FILENAME = N'C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\DATA\NEW_DB_log.ldf')
 FOR ATTACH
  
Successfully execute above sql we can easily rename database name and data files.
Share:

Thursday, May 30, 2013

Restore Sql server Database from .bak file using (T-Sql)


Database  has full backup .bak file. It can be restored using following two steps.
Step 1: Retrive the Logical file name of the database from backup.
RESTORE FILELISTONLY
FROM DISK = 'D:\BaakUpFile.bak'
GO

Step 2:
If you want replase this existing Database
RESTORE DATABASE AdventureWorks
FROM DISK = 'D:\BaakUpFile.bak'
WITH REPLACE
Or
Use the values in the LogicalName Column in following Step.
----Make Database to single user Mode
ALTER DATABASE DataBaseName
SET SINGLE_USER WITH
ROLLBACK IMMEDIATE

----Restore Database
RESTORE DATABASE DataBaseName
FROM DISK = 'D:\BaakUpFile.bak'
WITH MOVE 'DataBaseName' TO 'database location ... DataBaseName.mdf',
MOVE 'DataBaseName_log' database location ... DataBaseName_log.ldf'
/*If there is no error in statement before database will be in multiuser
mode.
If error occurs please execute following command it will convert
database in multi user.*/
ALTER DATABASE DataBaseName SET MULTI_USER
GO

If you want make new
RESTORE DATABASE DataBaseName
FROM DISK = 'D:\BaakUpFile.bak'
WITH MOVE 'DataBaseName' TO 'database location ... DataBaseName.mdf',
MOVE 'DataBaseName_log' database location ... DataBaseName_log.ldf'


Collect from : blog.sqlauthority.com
Share:

Friday, October 5, 2012

Finding Duplicates rows with SQL Server

This article shows how to find duplicated rows in a database table. This is a very common beginner question. Here is a useful sql query to help identify duplicate values in a column and return a count of the number of times that value appears.Following query demonstrates usage of GROUP BY, HAVING in one query and returns the results with duplicate column .  



SELECT ColumeName, COUNT(ColumnName) TotalCount
FROM TableName
GROUP BY ColumeName
HAVING COUNT(ColumnName) > 1


Share:

Thursday, September 27, 2012

How to Add Auto Number Column in Asp.net GridView

While working in ASP.NET, you often come across a need to display serial number or Auto-number in a Gridview control. This can be accomplished by adding the Container.DataItemIndex  in the html markup of the Gridview control.

<asp:TemplateField>
     <ItemTemplate>
 <%# Container.DataItemIndex + 1 %>
     </ItemTemplate>
 </asp:TemplateField>
Share:

SQL server Connecting from Another Computer

Configure SQL Server to listen on a specific port
  1. In SQL Server Configuration Manager, expand SQL Server Network Configuration, and then click on the server instance you want to configure.
  2. In the right pane, double-click TCP/IP.
  3. In the TCP/IP Properties dialog box, click the IP Addresses tab.
  4. In the TCP Port box of the IPAll section, type an available port number. For this tutorial, we will use 49172.
  5. Click OK to close the dialog box, and click OK to the warning that the service must be restarted.
  6. In the left pane, click SQL Server Services.
  7. In the right pane, right-click the instance of SQL Server, and then click Restart. When the Database Engine restarts, it will listen on port 49172.

To open a port in the Windows firewall for TCP access

Step 1
  1. On the Start menu, click Run, type WF.msc, and then click OK.
  2. In the Windows Firewall with Advanced Security, in the left pane, right-click Inbound Rules, and then click New Rule in the action pane.
  3. In the Rule Type dialog box, select Port, and then click Next.
  4. In the Protocol and Ports dialog box, select TCP. Select Specific local ports, and then type the port number of the instance of the Database Engine. Type 1433 for the default instance. Type 49172 if you are configuring a named instance and configured a fixed port in the previous task. Click Next.
  5. In the Action dialog box, select Allow the connection, and then click Next.
  6. In the Profile dialog box, select any profiles that describe the computer connection environment when you want to connect to the Database Engine, and then click Next.
  7. In the Name dialog box, type a name and description for this rule, and then click Finish.


Setp 2:

  1. On the Start menu, click Control Panel.
  2. In Control Panel, click Network and Internet Connections, and then open Windows Firewall.
  3. In Windows Firewall, click the Exceptions tab, and then click Add Port.
  4. In the Add a Port dialog box, in the Name box, type SQL Server "instanceName".
  5. In the Port number box, type the port number of the Database Engine instance. Type 1433 for the default instance. Type 49172 if you are configuring a named instance and configured a fixed port in the previous task. Verify that TCP is selected, and then click OK.


Share:

Wednesday, September 26, 2012

Set date format in jquery ui datepicker


The jQuery UI Datepicker is a highly configurable plugin that adds datepicker functionality to your pages.  You can customize the date format.
  1. d – day of month (single digit where applicable)
  2. dd – day of month (two digits)
  3.  o – day of the year (no leading zeros)
  4. oo – day of the year (three digit)
  5. m – month of year (single digit where applicable)
  6. mm – month of year (two digits)
  7.  y – year (two digits)
  8.  yy – year (four digits)
  9. D – short day name
  10.  DD – full day name
  11.  M – short month name
  12.  MM – long month name
  13.  '...' – any literal text string
  14.  @ - UNIX timestamp (milliseconds since 01/01/1970)
  15. ! – Windows ticks (100ns since 01/01/0001)


 (function(){
    var pickerOpts = {
       dateFormat:"d MM yy"
    };
    $("#date").datepicker(pickerOpts);
 });



predefined date formats for datepicker
The complete set of predefined date formats
Option value
Date format
$.datepicker.ATOM
"yy-mm-dd"
$.datepicker.COOKIE
"D, dd M y"
$.datepicker.ISO_8601
"yy-mm-dd"
$.datepicker.RFC_822
"D, d M y"
$.datepicker.RFC_850
"DD, dd-M-y"
$.datepicker.RFC_1036
"D, d M y"
$.datepicker.RFC_1123
"D, d M yy"
$.datepicker.RFC_2822
"D, d M yy"
$.datepicker.RSS
"D, d M y"
$.datepicker.TIMESTAMP
@ (UNIX timestamp)
$.datepicker.W3C
"yy-mm-dd"

Share:

Game Reviews

BTemplates.com

Powered by Blogger.

Search This Blog

Video Of Day

Find Us OIn Facebook

Blogroll

Contact

Tackle the Web with up to 5 new .COMs, $5.99 for the 1st year!

Advertisement