The use of keystroke dynamics for user authentication has evolved over the years and has found its application in mobile phones. But the primary challenge with mobile phones is that they can be used in any position. Thus, it becomes critical to analyze the use of keystroke dynamics using the data collected in various typing positions. This research proposed a three-step authentication model that could be used to authenticate a user who is using the mobile in sitting, walking, and relaxing position. Furthermore, the mobile orientation (portrait and landscape) was considered while taking input from the user. Apart from using traditional keystroke features, accelerometer data were also combined for classification using Random Forest(RF) and K-Nearest Neighbour(KNN) classifiers. The three-step authentication method was able to authenticate a user with an EER of 2.9% for the relaxing landscape position. Finally, the model was optimized using Particle Swarm Optimization (PSO) to reduce the feature set and make the model more practical for mobile phones. Optimization helped to reduce the number of features from 55 to 17 and improved the EER to 2.2%. The research validated that relaxing and walking positions are the best positions to authenticate a user using keystroke dynamics.