As a Portuguese speaker, I would pronounce both pan and pen the same.
In what can I base my pronunciation so I don't mistakenly pronounce these words the same again?
First, it might help to listen to the difference between the two words, since Portuguese may have different vowel sounds. An audio clip for pen can be found here. A similar audio clip for pan is here.
Next, the two vowel sounds are represented differently in the International Phonetic Alphabet (IPA). However, since the IPA represents all the sounds in every language, there are words from Portuguese which can show the difference. First, the sound from pen is written
Depending on your dialect, the sound from pan may be very similar. Wikipedia notes that the vowel sound from pan sounds like the first vowel of the Portuguese pedra, but that this vowel may also seem very close to the sound from pen. If this is the case for you, I suggest listening to the other words from this page, which provide words from other languages which use the same vowel. It could help you hear the difference.
Hopefully hearing the vowel sounds on their own, as well in context (in perhaps another language you already know) will help you learn to pronounce them. Otherwise, a speech therapist could possibly help you learn to form the vowels differently.