Hash.SHA1
---------

Calculated SHA-1 hash of given text.

| Component | Version | macOS | Windows | Linux | Server | iOS SDK |
|---|---|---|---|---|---|---|
| [Hash](component_Hash.md) | [3.1](newinversion31.md) | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes |

MBS( "Hash.SHA1"; Text { ; Flags } ) 

**MBS**( **"Hash.SHA1"** /\* Calculated SHA-1 hash of given text. \*/  
**$Text**; /\* The text to process. e.g. "Hello World" \*/   
**$Flags**) /\* Optional; Various flags you can combine by addition.  
Pass 1 for getting result Base64 encoded instead of Hex encoded.  
Pass 2 if input data is Hex encoded and plugin should decode it first.  
Pass 8 for base64URL encoding. (new in v10.3) e.g. 0 \*/ 

### Parameters

| Parameter | Description | Example | Flags |
|---|---|---|---|
| Text | The text to process. | "Hello World" |  |
| Flags | Various flags you can combine by addition.   Pass 1 for getting result Base64 encoded instead of Hex encoded.   Pass 2 if input data is Hex encoded and plugin should decode it first.   Pass 8 for base64URL encoding. (new in v10.3) | 0 | Optional |

### Result

Returns SHA-256 hash.

### Description

Calculated SHA-1 hash of given text.  
Text is converted to UTF-8 to make sure the text encoding doesn't change the hash value.  
Hashes are used to store a fingerprint of some data. When hashes are not equal, the data is probably also not equal.   
This function is good to make hashes for passwords. You don't save the password in your database, but only the hash. On login, you calculate the hash for the password entered by the user and compare the hash with the stored one. This way the database only contains hashes. And it's unlikely someone finds the password given the hash, except for easy cases like "hello" where google will tell you the text for the hash.  
To make hashes more secure, use a prefix/suffix like the user id or simply your application name. This way even hello as a password will be quite impossible to recover from the hash.  
SHA-1 is stronger than MD5 and weaker than SHA-512.  
  
Please be aware that text can result in different hashes if it contains line endings. You may want to make sure that line endings are right with the [Text.ReplaceNewLine](TextReplaceNewLine.md) function before you compare hashes to results in other development tools. FileMaker uses Mac line endings by default and most examples for JavaScript use Unix line endings.  
### Examples

Calculate hash of password:

 MBS ( "Hash.SHA1"; $password )  
Calculate empty hash:

 MBS ("Hash.SHA1"; "")  
<small>  
Example result: DA39A3EE5E6B4B0D3255BFEF95601890AFD80709</small>Calculate empty hash as Base64:

 MBS ("Hash.SHA1"; ""; 1)  
<small>  
Example result: "2jmj7l5rSw0yVb/vlWAYkK/YBwk="</small>Calculate for two similar texts:

 MBS ("Hash.SHA1"; "Franz jagt im komplett verwahrlosten Taxi quer durch Bayern")  
<small>  
Example result: 68AC906495480A3404BEEE4874ED853A037A7A8F</small>Calculate for two similar texts:

 MBS ("Hash.SHA1"; "Frank jagt im komplett verwahrlosten Taxi quer durch Bayern")  
<small>  
Example result: D8E8ECE39C437E515AA8997C1A1E94F1ED2A0E62</small>Encode Password like in PHP:

 # original in PHP:   
\#   
\# $nonce\_date\_pwd = pack("A\*",$nonce ) . pack("A\*",$CREATIONDATE ) . pack("H\*", sha1($password ));   
\# $PASSWORDDIGEST = base64\_encode( pack('H\*', sha1($nonce\_date\_pwd )));   
\#   
\# in FileMaker:   
\#   
\# you can use [Hash.RandomHexString](HashRandomHexString.md) to make your Nonce.   
\#   
Set Variable \[ $NonceHexEncoded ; Value: MBS ("[Text.EncodeToHex](TextEncodeToHex.md)"; Password Digest::Nonce ) \]   
Set Variable \[ $CreationDateHexEncoded ; Value: MBS ("[Text.EncodeToHex](TextEncodeToHex.md)"; Password Digest::CreationDate ) \]   
Set Variable \[ $PasswordHashHexEncoded ; Value: MBS ( "Hash.SHA1"; Password Digest::Password ; 0 ) \]   
Set Variable \[ $Input ; Value: $NonceHexEncoded &amp; $CreationDateHexEncoded &amp; $PasswordHashHexEncoded \]   
\# build hash by decoding from Hex, doing SHA1 and encode back to Base64   
Set Variable \[ $PasswordDigest ; Value: MBS ( "[Hash.Digest](HashDigest.md)"; "SHA1"; "hex"; $input ; ""; "Base64"; "" ) \]   
Set Field \[ Password Digest::PasswordDigest ; $PasswordDigest \]  
FileMaker 16 vs. Plugin:

 # MBS Plugin:   
Set Variable \[ $r1 ; Value: MBS ( "Hash.SHA1"; "Hello World")\]  
\# Same via FileMaker 16 native:   
Set Variable \[ $r2 ; Value: HexEncode( CryptDigest ( "Hello World"; "SHA1" ))\]  
### See also

- [Hash.Digest](HashDigest.md)
- [Hash.RandomHexString](HashRandomHexString.md)
- [Hash.SHA1.HMAC](HashSHA1HMAC.md)
- [Hash.SHA512](HashSHA512.md)
- [Text.EncodeToHex](TextEncodeToHex.md)
- [Text.ReplaceNewLine](TextReplaceNewLine.md)

### Release notes

- **Version 10.3**
    - Added option for Base64URL encoding to [Hash.MD5](https://www.mbsplugins.eu/HashMD5.shtml), [Hash.MD5.HMAC](https://www.mbsplugins.eu/HashMD5HMAC.shtml), [Hash.SHA1](https://www.mbsplugins.eu/HashSHA1.shtml), [Hash.SHA1.HMAC](https://www.mbsplugins.eu/HashSHA1HMAC.shtml), [Hash.SHA256](https://www.mbsplugins.eu/HashSHA256.shtml), [Hash.SHA256.HMAC](https://www.mbsplugins.eu/HashSHA256HMAC.shtml), [Hash.SHA512](https://www.mbsplugins.eu/HashSHA512.shtml) and [Hash.SHA512.HMAC](https://www.mbsplugins.eu/HashSHA512HMAC.shtml) functions.

### Blog Entries

- [MBS FileMaker Plugin, version 10.3pr1](https://www.mbsplugins.de/archive/2020-06-01/MBS_FileMaker_Plugin_version_1/monkeybreadsoftware_blog_filemaker)
- [MBS Filemaker Plugin, version 3.2pr7](https://www.mbsplugins.de/archive/2013-04-16/MBS_Filemaker_Plugin_version_3/monkeybreadsoftware_blog_filemaker)

This function is free to use.

Created 18th August 2014 , last changed 25th February 2026

  
[Hash.RandomString](HashRandomString.md) - [Hash.SHA1.HMAC](HashSHA1HMAC.md)

[HTML Version](HashSHA1.shtml)