Sunday, 7 April 2013

Common English mistake using: Alumni

Singular male:     Alumnus
Plural male:        Alumni

Singular female:  Alumna
Plural female:     Alumnae


What about using the informal abbreviation for all?! ;)  Alum

Feature I would like to see in: iPad

Multiple profiles, especially for the e-mails, and if possible for other accounts like Facebook, Twitter,...etc.

So that when I use the device I can activate my profile while my spouse switches to her profile when she needs to use it. (A personalized experience per user)

Thursday, 4 April 2013

Look-up tables design

1- No to a single look-up table:
   a - Scalability.
   b - Data Maintainability (Error prone)

2- Integrity on deletion:
   a - Deletion stored procedure with the logic to restrict deletion for consumed records.
   (The reason that foreign keys are not enough since typically they reside within a single DB; however, references are usually consumed from other DBs.) [My recommendation]
   b- Don't delete: Just mark as deleted or add a status per record to be defined by the business.
    

Monday, 1 April 2013

Photo Quiz: Which country is this?!



I'm not sure whether there are also any clue to ask:
Which city is this? 

Create iPhone Tone

1- Select a music file from iTunes.

2- (Optional) Context Menu "Get Info", then set both Start Time and Stop Time.
Tip: Maximum Tone length is 40 seconds.

3) Context Menu "Create AAc Version"

4) Within iTunes Media Folder "...\iTunes Media\Music\Your Song Name", change the file extension from ".m4a" to ".m4r"

5) Drag and Drop the file into the iTunes library and sync. (You now have a new Tone in the Tones library section)

Wednesday, 27 March 2013

To identify the mpm module loaded for an Apache server under windows

>"C:\Program Files (x86)\Apache Software Foundation\Apache2.2\bin\httpd.exe" -l

Compiled in modules:
  core.c
  mod_win32.c
  mpm_winnt.c
  http_core.c
  mod_so.c

Thursday, 21 March 2013

Displaying Solutions for ASP.NET web applications

Visual Studio --> Tools --> Options



Validating users using password, hash and salt


DB Fields:
Table User: Columns (UserName, Password, Salt)


Public Shared Function GetPasswordHash(Password As String, Salt As String) As String
Dim StringEncoder As New UTF8Encoding()
Dim Bytes_Password As Byte() = StringEncoder.GetBytes(Password)
Dim Bytes_Salt As Byte() = StringEncoder.GetBytes(Salt)

' Array for password & salt
Dim Bytes_Password_Salt As Byte() = New Byte(Bytes_Password.Length + Bytes_Salt.Length - 1) {}

For i As Integer = 0 To Bytes_Password.Length - 1
    Bytes_Password_Salt(i) = Bytes_Password(i)
Next

For i As Integer = 0 To Bytes_Salt.Length - 1
      Bytes_Password_Salt(i + Bytes_Password.Length) = Bytes_Salt(i)
Next

Dim MD5Provider As New MD5CryptoServiceProvider
Dim Bytes_Hash As Byte() = MD5Provider.ComputeHash(Bytes_Password_Salt)
Dim String_Hash As String = Convert.ToBase64String(Bytes_Hash)

Return String_Hash
End Function

Public Shared Function ValidateUser(UserName As String, Password As String) As Boolean
Dim IsValidUser As Boolean = False

Dim Cmd As New SqlCommand()
Cmd.CommandText = "SELECT [Password] PassHash, Salt AS Salt FROM [User] WHERE UPPER(UserName) = UPPER(@UserName) "
Cmd.CommandType = Data.CommandType.Text

Cmd.Parameters.AddWithValue("UserName", UserName)

Dim ds As DataSet = DBHelper.RunSQLQuery(Cmd)

Dim StoredHash As String = Nothing
Dim StoredSalt As String = Nothing
If ds.Tables.Count = 1 Then
    If ds.Tables(0).Rows.Count = 1 Then

       Dim CurrentRow As DataRow = ds.Tables(0).Rows(0)
       If Not IsDBNull(CurrentRow("PassHash")) Then
               StoredHash = CurrentRow("PassHash")
        End If

       If Not IsDBNull(CurrentRow("Salt")) Then
                StoredSalt = CurrentRow("Salt")
       End If
   End If
End If

If Not IsNothing(StoredHash) And Not IsNothing(StoredSalt) Then
   Dim CalculatedHash As String = GetPasswordHash(Password, StoredSalt)
   If CalculatedHash = StoredHash Then
        IsValidUser = True
   End If
End If

Return IsValidUser
End Function


Public Shared Function RunSQLQuery(ByVal Cmd As SqlCommand) As System.Data.DataSet
Dim s As New System.Data.DataSet()

Cmd.Connection = New SqlConnection(ConnectionString)
Dim a As New System.Data.SqlClient.SqlDataAdapter(Cmd)
a.Fill(s)

Return s
End Function