diff --git a/smtp.admin.inc b/smtp.admin.inc
index 9d556f7..794ecf6 100644
--- a/smtp.admin.inc
+++ b/smtp.admin.inc
@@ -4,6 +4,127 @@
  * Administrative page code for the smtp module.
  *
  */
+
+require_once 'smtp.functions.inc';
+
+/**
+ * Custom page callback function.
+ *
+ * @return array
+ *   "$build" An array of form constructors.
+ *
+ * @see smtp_menu()
+ */
+function smtp_custom_forms_callback() {
+  $build = array(
+	'form_one' => drupal_get_form('smtp_set_key_form'),
+    'form_two' => drupal_get_form('smtp_set_password_form'),
+	'form_three' => drupal_get_form('smtp_admin_settings'),
+  );
+  return $build;
+}
+
+/**
+ * Form constructor for the Set Key form.
+ *
+ * @see smtp_menu()
+ */
+function smtp_set_key_form($form, &$form_state) {
+  
+  $form['key'] = array(
+      '#type'  => 'fieldset',
+      '#title' => t('Password encryption key'),
+  );
+  $form['key']['smtp_key'] = array(
+    '#type' => 'textfield',
+	'#title' => t('Key'),
+	'#default_value' => variable_get('smtp_key', ''),
+	'#description' => t('32 alphnumeric upper and lower case characters.  Required for encrypting your password for storage in the database.') . '<br/>'
+	  . t('You can leave it alone if your smtp server does not require authentication. If you reset the key also reset the password. '. '<br/>'
+	  .'Only one key is needed.'),
+  );
+  $form['key']['submit'] = array(
+	'#type' => 'submit',
+	'#value' => t('Set key'),
+  );
+  return $form;
+}
+
+/**
+ * Form validation handler for smtp_set_key_form().
+ *
+ * @see smtp_set_key_form_submit()
+ */
+function smtp_set_key_form_validate($form, &$form_state) {
+  if (drupal_strlen($form_state['values']['smtp_key']) != 32) {
+    form_set_error('smtp_key', t('Key must be 32 characters.'));
+  }
+  if (!ctype_alnum($form_state['values']['smtp_key'])) {
+    form_set_error('smtp_key', t('Key must all alphanumeric characters.'));
+  }
+}
+
+/**
+ * Form submit handler for smtp_set_key_form().
+ *
+ * @see smtp_set_key_form_validate()
+ */
+function smtp_set_key_form_submit($form, &$form_state) {
+  smtp_set_key($form_state['values']);
+}
+
+/**
+ * Form constructor for the Set Password form.
+ *
+ * @see smtp_menu()
+ */
+function smtp_set_password_form($form, &$form_state) {
+  $password = smtp_get_password(0);
+  if ($password) {
+    $password = t('Password is set.');
+  }
+  else {
+    $password = t('Password is not set.');
+  }
+
+  $form['password'] = array(
+      '#type'  => 'fieldset',
+      '#title' => t('SMTP password'),
+  );
+  $form['password']['smtp_password'] = array(
+      '#type' => 'textfield',
+      '#title' => t('Password'),
+      '#default_value' => $password,
+      '#attributes' => array('autocomplete' => 'off'),
+      '#description' => t('This is set seperately so it can be stored securely in the database.'),
+  );
+  $form['password']['submit'] = array(
+      '#type' => 'submit',
+      '#value' => t('Set password'),
+  );
+  return $form;
+}
+
+/**
+ * Form validation handler for smtp_set_password_form().
+ *
+ * @see smtp_set_password_form_submit()
+ */
+function smtp_set_password_form_validate($form, &$form_state) {
+  if (empty($form_state['values']['smtp_password'])) {
+    unset($form_state['values']['smtp_password']);
+  }
+}
+
+/**
+ * Form submit handler for smtp_set_password_form().
+ *
+ * @see psmtp_set_password_form_validate()
+ */
+function smtp_set_password_form_submit($form, &$form_state) {
+  smtp_set_password($form_state['values']);
+}
+
 /**
  * Administrative settings.
  *
@@ -105,13 +226,6 @@ function smtp_admin_settings() {
     '#default_value' => variable_get('smtp_username', ''),
     '#description'   => t('SMTP Username.'),
   );
-  $form['auth']['smtp_password'] = array(
-    '#type'          => 'password',
-    '#title'         => t('Password'),
-    '#default_value' => variable_get('smtp_password', ''),
-    '#description'   => t('SMTP password. Leave blank if you don\'t wish to change it.'),
-  );
-
   $form['email_options'] = array(
     '#type'  => 'fieldset',
     '#title' => t('E-mail options'),
@@ -167,8 +281,6 @@ function smtp_admin_settings() {
   return system_settings_form($form);
 }  //  End of smtp_admin_settings().
 
-
-
 /**
  * Validation for the administrative settings form.
  *
@@ -189,15 +301,4 @@ function smtp_admin_settings_validate($form, &$form_state) {
   if ($form_state['values']['smtp_from'] && !valid_email_address($form_state['values']['smtp_from'])) {
     form_set_error('smtp_from', t('The provided from e-mail address is not valid.'));
   }
-  // If username is set empty, we must set both username/password empty as
-  // as well.
-  if (empty($form_state['values']['smtp_username'])) {
-    $form_state['values']['smtp_password'] = '';
-  }
-  // A little hack. When form is presentend, the password is not shown (Drupal way of doing).
-  // So, if user submits the form without changing the password, we must prevent it from being reset.
-  elseif (empty($form_state['values']['smtp_password'])) {
-    unset($form_state['values']['smtp_password']);
-  }
 }  //  End of smtp_admin_settings_validate().
-
diff --git a/smtp.functions.inc b/smtp.functions.inc
new file mode 100755
index 0000000..40d28bf
--- /dev/null
+++ b/smtp.functions.inc
@@ -0,0 +1,174 @@
+<?php
+/**
+ * @file
+ * Functions required by the SMTP Authorization Project.
+ */
+
+/**
+ * Sets ecryption key and IV.
+ *
+ * @see smtp_set_key_form()
+ */
+function smtp_set_key($form_values) {
+  $exists = db_query('SELECT value FROM {variable} WHERE name = :smtp_iv', array(':smtp_iv' => 'smtp_iv'))->fetchField();
+  $alg = MCRYPT_RIJNDAEL_256;
+  $iv = mcrypt_create_iv(mcrypt_get_iv_size($alg, MCRYPT_MODE_ECB), MCRYPT_RAND);
+  $smtp_key = $form_values['smtp_key'];
+  if ($smtp_key) {
+    variable_set('smtp_key', $smtp_key);
+    drupal_set_message(t('Key was set succesfully.'));
+  }
+  else {
+    drupal_set_message(t('There was a problem setting the key.'), 'error');
+  }
+  if ($exists) {
+    // This causes a Notice error.
+    variable_del('smtp_iv');
+    smtp_insert_iv($iv);
+  }
+  else {
+    smtp_insert_iv($iv);
+  }
+}
+
+/**
+ * Inserts IV into the database.
+ *
+ * @param string $iv
+ *   $iv Random binary string.
+ *
+ * @see smtp_set_key()
+ */
+function smtp_insert_iv($iv) {
+  $result = db_insert('variable')->fields(array(
+      'name' => 'smtp_iv',
+      'value' => $iv,))
+      ->execute();
+  if ($result == NULL) {
+    drupal_set_message(t('There was a problem setting the initialization vector.'), 'error');
+  }
+  else {
+    drupal_set_message(t('Initialization vector was set succesfully.'));
+  }  
+}
+
+/**
+ * Fetches key and IV from the database.
+ *
+ * @return array
+ *   $key Array $key['key'] and $key['iv'].
+ *
+ * @see smtp_encrypt()
+ * @see smtp_decrypt()
+ */
+function smtp_get_key() {
+  $result = db_query('SELECT value FROM {variable} WHERE name = :smtp_iv', array(':smtp_iv' =>'smtp_iv'));
+  if ($iv = $result->fetchField()) {
+    $key = array(
+      'key' => variable_get('smtp_key', NULL),
+      'iv' => $iv,
+    );
+    return $key;
+  }
+  else {
+    drupal_set_message(t('There was a problem getting the key.'), 'error');
+  }  
+}
+
+/**
+ * Password is passed in then returns encryted string.
+ *
+ * @param string $string
+ *   $string User defined password.
+ *
+ * @return string
+ *   $encrypted_string Encrypted using PHP's mcrypt_encrypt().
+ */
+function smtp_encrypt($string) {
+  $key = smtp_get_key();
+  $alg = MCRYPT_RIJNDAEL_256;
+  if ($encrypted_string = mcrypt_encrypt($alg, $key['key'], $string, MCRYPT_MODE_CBC, $key['iv'])) {
+    return $encrypted_string;
+  }
+  else {
+    drupal_set_message(t('Unable to encrypt string.'), 'error');
+  }
+}
+
+/**
+ * Encrypted string is passed in then returns decryted string.
+ *
+ * @param string $encrypted_string
+ *   $encrypted_string Encrypted password is fetched from the database.
+ *
+ * @return string
+ *   $decrypted_string Decrypted using PHP's mcrypt_decrypt().
+ */
+function smtp_decrypt($encrypted_string) {
+  $key = smtp_get_key();
+  $alg = MCRYPT_RIJNDAEL_256;
+  if ($decrypted_string = mcrypt_decrypt($alg, $key['key'], $encrypted_string, MCRYPT_MODE_CBC, $key['iv'])) {
+    return $decrypted_string;
+  }
+  else {
+    drupal_set_message(t('Unable to decrypt string.'), 'error');
+  }
+}
+
+/**
+ * Stores SMTP password in the database.
+ *
+ * @see smtp_set_password_form()
+ */
+function smtp_set_password($form_values) {
+  $exists = db_query('SELECT value FROM {variable} WHERE name = :smtp_password', array(':smtp_password' => 'smtp_password'))->fetchField();
+  $encrypted_password = smtp_encrypt($form_values['smtp_password']);
+  if ($exists) {
+    // This causes a Notice error.
+    variable_del('smtp_password');
+    smtp_insert_password($encrypted_password);
+  }
+  else {
+    smtp_insert_password($encrypted_password);
+  }
+}
+
+/**
+ * Inserts password into the database.
+ *
+ * @param string $password
+ *   $password User definde password.
+ *
+ * @see smtp_set_password()
+ */
+function smtp_insert_password($password) {
+  $result = db_insert('variable')->fields(array(
+    'name' => 'smtp_password',
+    'value' => $password,))
+    ->execute();
+  if ($result == NULL) {
+    drupal_set_message(t('There was a problem setting the password.'), 'error');
+  }
+  else {
+    drupal_set_message(t('Password was set succesfully.'));
+  }
+}
+
+/**
+ * Fetches encrypted password from the database and decrypts it.
+ * 
+ * @param boolean $error
+ *   $error If 0 is passed in error message message will not be displayed.
+ */
+function smtp_get_password($error) {
+  $result = db_query('SELECT value FROM {variable} WHERE name = :smtp_password', array(':smtp_password' =>'smtp_password'));
+  if($encrypted_password = $result->fetchField()) {
+    $password = smtp_decrypt($encrypted_password);
+    return $password;
+  }
+  else {
+    if ($error == 1) {
+      drupal_set_message(t('There was a problem getting the password.'), 'error');
+    }
+  }  
+}
diff --git a/smtp.info b/smtp.info
index c91efd2..bed0d66 100644
--- a/smtp.info
+++ b/smtp.info
@@ -8,3 +8,4 @@ files[] = smtp.admin.inc
 files[] = smtp.mail.inc
 files[] = smtp.phpmailer.inc
 files[] = smtp.transport.inc
+files[] = smtp.functions.inc
diff --git a/smtp.install b/smtp.install
index 2a68650..435898d 100644
--- a/smtp.install
+++ b/smtp.install
@@ -30,6 +30,8 @@ function smtp_uninstall() {
   variable_del('smtp_protocol');
   variable_del('smtp_test_address');
   variable_del('smtp_username');
+  variable_del('smtp_iv');
+  variable_del('smtp_key');
 
   if (variable_get('smtp_library', '') == drupal_get_path('module', 'smtp') . '/smtp.module') {
     variable_del('smtp_library');
diff --git a/smtp.mail.inc b/smtp.mail.inc
index b085b47..8fe82e3 100644
--- a/smtp.mail.inc
+++ b/smtp.mail.inc
@@ -5,6 +5,8 @@
  *
  */
 
+require_once 'smtp.functions.inc';
+
 /**
 * Modify the drupal mail system to use smtp when sending emails.
 * Include the option to choose between plain text or HTML
@@ -458,7 +460,7 @@ class SmtpMailSystem implements MailSystemInterface {
 
     // Set the authentication settings.
     $username = variable_get('smtp_username', '');
-    $password = variable_get('smtp_password', '');
+    $password = smtp_get_password(1);
 
     // If username and password are given, use SMTP authentication.
     if ($username != '' && $password != '') {
diff --git a/smtp.module b/smtp.module
index 8527d83..d40f712 100644
--- a/smtp.module
+++ b/smtp.module
@@ -31,8 +31,8 @@ function smtp_help($path, $arg) {
 function smtp_menu() {
   $items['admin/config/system/smtp'] = array(
     'title'            => 'SMTP Authentication Support',
-    'page callback'    => 'drupal_get_form',
-    'page arguments'   => array('smtp_admin_settings'),
+    'page callback'    => 'smtp_custom_forms_callback',
+    //'page arguments'   => array('smtp_admin_settings'),
     'access arguments' => array('administer smtp module'),
     'description'      => 'Allow for site emails to be sent through an SMTP server of your choice.',
     'file'             => 'smtp.admin.inc',
