User Tools

Site Tools


28.2.2 Application Crypt.MD5

In this chapter you will learn about an application that uses methods of the Crypt class. They are the methods Crypt.MD5 and Crypt.Check(Password As String, Crypt As String). With the method Crypt.Check(..) you can check whether an entered password - which is internally encrypted according to the algorithm MD5 - matches an encrypted password stored in the programme or in a file or not. The programme presented is protected by a strong (start) password (+Gambas340):

Figure Password input (plain text)

Figure Password is correct

The start password used was generated with the MD5 password generator with random prefix. This encrypted password is permanently stored in the programme. In addition, the following enhancements have been implemented:

  • The password check only allows 3 invalid entries. After that, the password query is terminated and the protected main programme is not started.
  • After successful password entry, the user can change the programme password in the main programme at runtime.

Figure The main programme has been successfully started …

In the following section, only excerpts from the source code are presented and briefly explained.

' Gambas class file
' The CRYPT and SETTINGS components must be included.
Public iCount As Integer = 1
Public sMD5Password As String
Public bPWCancle As Boolean = False
Public bPWInputError As Boolean = False
Public pw2Settings As New Settings(Application.Path &/ ".pw.conf")
' Hint: The file .pw.conf is a hidden file in the application path
Public Sub Form_Open()
  FGetPassword.Resizable = False
  PictureBox1.Picture = Picture["Symbols/lock_zu.png"]
  txtPasswordInput.Password = True
  sMD5Password = pw2Settings["Password/MD5-Password", "$1$V/eCyFQp$hDAEMfcO7yuN3o0UFfkKL0"]
End ' Form_Open
Public SubbtnCancle_Click()
  bPWCancel = True
End ' btnCancel_Click()
Public Sub txtPasswordInput_Activate()
End ' Input_Activate
Public Sub btnOK_Click()
  Dim sPasswort, sMessage As String
  sPassword = txtPasswordInput.Text
  If sPassword = "" Then
     Message.Info("Enter a password!")
  Endif ' sPassword = "" ?
  If Crypt.Check(sPassword, sMD5Password) = True Then
     If iCount <= 2 Then
        Message.Warning("Attention!\nThe password is NOT correct!")
        txtPasswordInput txtPasswortEingabe.Clear
        Inc iCount
        sMessage = "Error!\n"
        sMessage &= "The password is NOT correct even after 3 entries!\n"
        sMessage &= "The password request is terminated."
        bPWInputError = True
     Endif ' iCount <= 2 ?
     bPWInputError = False
  Endif ' Crypt.Check(sPassword, sMD5Password) = True ?
End ' btnOK_Click
Public Sub Form_Close()
  If bPWAbort = True Or bPWInputError = True Then
     FMain.PasswordError = True
     PictureBox1.Picture = Picture["Symbols/lock_up.png"]
     FGetPassword.text = "The main programme is started..."
     Wait 2
  Endif ' Fehler ?
End ' Form_Close()


  • At the 1st programme start and the following ones, the md5-encrypted password stored in the programme is used → “$1$V/eCyFQp$hDAEMfcO7yuN3o0UFfkKL0” as long as no new password has been generated by the user.
  • The query programme is terminated when the user exits the password query or when, after 2 incorrect entries, the 3rd entry also resulted in a password error or the correct password was entered.
  • The function Crypt.Check(…) returns True if the password pair does NOT match (!) and False if the encrypted stored password matches the md5-encrypted plaintext input!
  • The query in the Form_Close procedure is important because under no circumstances should the password query be bypassed.

A new password can be generated by the user in the main program:

Figure A new programme password is generated.

A modified MD5 password generator is used, which was already described in chapter 28.2.1. The component gb.settings is used for convenient reading and saving of the reference password. The new, strong password - encrypted according to MD5 - is stored in the configuration file .pw.conf in the application directory.




The website uses a temporary session cookie. This technically necessary cookie is deleted when the browser is closed. You can find information on cookies in our privacy policy.
k28/k28.2/k28.2.2/start.txt · Last modified: 30.01.2022 (external edit)

Page Tools