Click here to view and discuss this page in DocCommentXchange. In the future, you will be sent there automatically.

SQL Anywhere 10.0.1 » SQL Anywhere Server - SQL Reference » SQL Functions » Alphabetical list of functions

GROUPING function [Aggregate] Next Page

HASH function [String]


Returns the specified value in hashed form.

Syntax

HASH( string-expression[, algorithm ] )

Parameters

string-expression    The value to be hashed. This parameter is case sensitive, even in case-insensitive databases.

algorithm    The algorithm to use for the hash. Possible values include: MD5, SHA1, SHA1_FIPS, SHA256, SHA256_FIPS. By default, the MD5 algorithm is used.

Note

The FIPS algorithms are only for use on systems using FIPS 140-2 certified software from Certicom. You must specify the -fips option when starting the database server to use the FIPS algorithms.

Remarks

Using a hash converts the value to a byte sequence that is unique to each value passed to the function.

If the server was started with the -fips option, the algorithm used, or the behavior, may be different, as follows:

Following are the return types, depending on the algorithm used:

Caution    

All of the algorithms are one-way hashes. It is not possible to re-create the original string from the hash.

See also
Standards and compatibility
Example

The following example creates a table called user_info to store information about the users of an application, including their user ID and password. One row is also inserted into the table. The password is hashed using the HASH function and the SHA256 algorithm. Storing hashed passwords in this way can be useful if you do not want to store passwords in clear text, yet you have an external application that needs to compare passwords.

CREATE TABLE user_info ( 
  employee_id   INTEGER NOT NULL PRIMARY KEY,
  user_name CHAR(80),
  user_pwd CHAR(80) );
INSERT INTO user_info 
  VALUES ( '1', 's_phillips', HASH( 'mypass', 'SHA256' ) );