Android Code Snippet Creating/sharing passwords with the help of an image

I'm just playing arround with encrypting/decrypting. After creating some strong passwords I asked myself how to transmit passwords in a anonymous way.

First idea was Bluetooth but in that case the other device has to be in reach. Sending it via mail or other platforms will (at least) leave traces.

So why not use a picture you took?

1. Send/share this pic to another device (take care it will not abe modified)
2. Store it in the gallery
3. in your app call ContentChooser to let the user select that image
4. Get the bytes of the image
5. From a known position get f.e. 100 bytes
6. You can use this string as a password (same pic - same password on all devices)
7. or use it for further encryption, etc.

B4X:
Sub choose_pic
    Dim chooser As ContentChooser
    If chooser.IsInitialized = False Then
        chooser.Initialize("chooser")
    End If
    chooser.Show("image/*", "Choose image")
End Sub
Sub chooser_Result(Success As Boolean, Dir As String, FileName As String)
If Success Then
    Dim pwpic As String
    Dim InputStream1 As InputStream
    InputStream1 = File.OpenInput(Dir, FileName)
    Dim OutputStream1 As OutputStream
    OutputStream1.InitializeToBytesArray(1000)
    File.Copy2(InputStream1, OutputStream1)
    Dim buffer() As Byte 'declares an empty array
    buffer = OutputStream1.ToBytesArray
    Log (buffer.Length)
    If buffer.Length<400 Then
      Msgbox("Please choose a pic with a size >=400 bytes","")
    Else 
      For i=1 To 100
          pwpic=pwpic&Chr(buffer(i+buffer.Length/2)+128) '+128 -> to get positive values
      Next
    End If
   
    Dim buffer() As Byte
   
   

Else
    ToastMessageShow("No image selected", True)
End If
End Sub

Add this permission to your manifest:

B4X:
AddPermission(android.permission.READ_EXTERNAL_STORAGE)
 

Mark Zraik

Member
Licensed User
Longtime User
Kind of a version of a retinal scan or finger print(Bio Match). Matching an image or array sequence against a known pattern. Cool!
So, you could use this as a login checker where the user would have to pick, or have the correct image in order to pass.

Interesting!
 

ivan.tellez

Active Member
Licensed User
Longtime User
Not really secure, someone could pick the correct picture at random.

Maybe if you do this with 4 or more pics and in the correct order.
 
Top