In general, yes, that pattern works for a simple authentication. The biggest downside is having the credentials hard-coded into the code and/or whether your code is public (as it would be if it were hosted on Streamlit sharing).
But for things that aren’t strictly private (like health information, financial, etc.), just that you don’t want people looking at, that pattern is fine.