Aiming towards increased robustness to noise and variability, this paper proposes a novel method for electrocardiogram-based authentication, based on an endto-end convolutional neural network (CNN). This network was trained either through the transfer of weights after identification training or using triplet loss, both novel for ECG biometrics. These methods were evaluated on three large ECG collections of diverse signal quality, with varying number of training subjects and user enrollment duration, as well as on cross-database application, with or without fine-tuning. The proposed model was able to surpass the state-of-the-art performance results on off-the-person databases, offering 7.86% and 15.37% Equal Error Rate (EER) on UofTDB and CYBHi, respectively, and attained 9.06% EER on the PTB on-the-person database. The results show the proposed model is able to improve the performance of ECG-based authentication, especially with offthe-person signals, and offers state-of-the-art performance in cross-database tests.