Sunday, July 29, 2012

Generating Hash in java using own salt

Generating hash value in java is very tedious task but it is very useful where we use random password or add some unique string with image name.In java, java.security provides differnet type of class and method for hash function.Salt is a value which helps in generate unique hash value .
I'm using MD5 with ShA-1 here.


import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.Date;
public class OwnHash{
public String generateHash(String input)
    {
        StringBuilder hash = new StringBuilder();
        String SALT = "vaaabbccddeeff";
        String NEWPASSWORD=SALT+input;

        try {
            MessageDigest sha = MessageDigest.getInstance("SHA-1");
            byte[] hashedBytes = sha.digest(NEWPASSWORD.getBytes());
            char[] digits = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
                    'a', 'b', 'c', 'd', 'e', 'f' };
            for (int idx = 0; idx < hashedBytes.length; ++idx)
            {
                byte b = hashedBytes[idx];
                hash.append(digits[(b & 0xf0) >> 4]);
                hash.append(digits[b & 0x0f]);

            }
        }
        catch (NoSuchAlgorithmException e)
        {
            // handle error here.
        }

        return hash.toString();
    }}

Mysql-JDBC connection in java

In java , jdbc connection is very simple , just add a mysql jar file in lib folder and make special class which return Connection type reference .in this example i'm using properties file to pass user name and password.
This is type 4 driver example bcoz it uses java  code to access data from MySql,

public Connection getdbConnection()
{
try {
   Class.forName("com.mysql.jdbc.Driver");
}
catch(ClassNotFoundException ex) {
   System.out.println("Error: unable to load driver class!");
   System.exit(1);
}
String URL = "jdbc:mysql://localhost:3306/";
Properties info = new Properties( );
info.put( "user", "username" );
info.put( "password", "password" );

Connection conn = DriverManager.getConnection(URL, info); 

return conn;
}
 
Complete Code is here :
 
import java.io.IOException;
import java.sql.*;


public class DBUtil {
 static Connection cn=null;
 
 public  Connection getConnect()
 {
   
   
  try {
   Class.forName("com.mysql.jdbc.Driver");
cn=DriverManager.getConnection("jdbc:mysql://localhost:3306/db","root","admin");
  } 
  catch(ClassNotFoundException se)
  {
   se.printStackTrace();
  }
  catch (SQLException e1) 
  {
   e1.printStackTrace();
  }
  return cn; 
 }
 
 

} 

Friday, October 29, 2010

Unlock Huawei modem


I've read many places where people r demanding money for unlocking modem.They write Email and Bank A/C details for money transfer, its funny.For only few digits they r charging money so I've decided to disclose all the science behind this.
Commonly the unlock code depends upon the IMEI no. and that IMEI no. uniquely identify each modem.
To calculate unlock code u can use online calculator from given url http://a-zgsm.com/huawei.php
or if u want to get own calculator, u can download from this link http://www.mediafire.com/?dtm5kwjmomx.
This is a universal calculator that can unlock Huawei,Nokia,Zte,Nec and others.
If u feel any problem u can write here.

Monday, October 25, 2010

Hosting own webserver without static IP

Hosting own server always a risky and expensive job but if u don't know hosting process you don't know any thing in real environment.Hosting is a process where we connect our own server to the web and people can access my site from my own server not any other.So here your responsibility is not only development but also to secure server.
This tutorial will teach you how can we publish own website -
1-) In the first step you'll create your website , it may be in any language.
2-)Now the next step, u have to purchase own Domain name like www.example.com . here example.com is your domain name.Domain price depend on the name like .com,.net,.org etc.
You can purchase it from godaddy or other.The payment can be done by VISA or MASTER card only .
3-)If u r not able to host own server u can purchase hosting environment and it depend on the language which u've used in web development.
if u have 24hours internet connection and a old computer u can create own webserver by installing Server program like APACHE and other and then u'll make environment according to your web application.If your website is written in PHP then u've to install Linux and then LAMP.
Linux is more secure as compare to other.
4-)Now the next step, u've to purchase Static IP for your Internet connection.and connect that server to your internet.In india BSNL,AIRTEL,MTNL etc provide Static IP.You can purchase from these.
5-)Now the final stage is to set your IP to that Domain which u purchased from Godaddy or other.They provides option to set your static IP for that Domain.
Now your server is ready to accept request from all over world.
If u don't have money to set own webserver due to Static Ip don't mind there is a another option
you can use http://dyndns.dk/ service. If u r using Broadband or other connection most of the time u'll get different IP when u start your internet .So http://dyndns.dk/ provides fascility where they'll give u domain name and u'll get register on this.Now whenever u'll start your system http://dyndns.dk/ will record your IP with your Domain name and when any user request for page first it'll go to the http://dyndns.dk/ with your Domain and then that request will come to your server.
Enjoy webhosting without Static IP....