title: How to verify if a username and password exists in my room database?
body: <p>I am practicing with the room database and it has been difficult for me to verify if a username and password exist in my database,(I am sure I have many errors for this reason I ask for your help) my code:</p>
  <p>//User</p>
  <pre><code>  @Entity(tableName = &quot;user_table&quot;)
      data class User(
              @PrimaryKey(autoGenerate = true)
              val id : Int ,
              val userName: String,
              val nameStudent: String,
              val grade: String,
              val password: String
      )
  </code></pre>
  <p>//UserDao
  v    @Dao
  interface UserDao {</p>
  <pre><code>        @Insert(onConflict = OnConflictStrategy.IGNORE)
          suspend fun addUser(user: User)
      
   @Query(&quot;SELECT * FROM user_table WHERE userName LIKE :name AND password LIKE :password&quot;)
          fun readAllData(name: String, password: String): User
          
      }
  </code></pre>
  <p>//UserRepository</p>
  <pre><code>   class UserRepository(private val userDao: UserDao,val name:String, val passWord:String) {
      
      val readAllData: List&lt;User&gt; = userDao.readAllData(name, passWord)
      
      suspend fun adduser(user: User) {
          userDao.addUser(user)
      }
  
  }
  </code></pre>
  <p>//UserViewModel</p>
  <pre><code> class UserViewModel(application: Application,  name:String, passWord:String) : AndroidViewModel(application) {
      
      val readAllData: List&lt;User&gt;
      private val repository: UserRepository
  
      init {
          val userDao = UserDatabase.getDatabase(
              application
          ).userDao()
          repository = UserRepository(userDao,name,passWord)
          readAllData = repository.readAllData
      }
  
      fun addUser(user: User) {
          viewModelScope.launch(Dispatchers.IO) {
              repository.adduser(user)
          }
      }
  
  }
  </code></pre>
  <p>//ViewModelFactory</p>
  <pre><code>class MyViewModelFactory(private var application: Application, private var name: String, private var passWord: String) :
      ViewModelProvider.Factory {
      override fun &lt;T : ViewModel?&gt; create(modelClass: Class&lt;T&gt;): T {
          if (modelClass.isAssignableFrom(UserViewModel::class.java)) {
              return UserViewModel(application, name, passWord) as T
          }
          throw IllegalArgumentException(&quot;Unknown ViewModel class&quot;)
      }
  }
  </code></pre>
  <p>//MainFragment</p>
  <pre><code> override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
  
          super.onViewCreated(view, savedInstanceState)
          binding = FragmentMainBinding.bind(view)
  
          val factory = MyViewModelFactory(Application(),&quot;&quot;,&quot;&quot;)
          mUserViewModel = ViewModelProvider(this,factory).get(UserViewModel::class.java)
  
          val name = binding.textInputUser.editText?.text.toString()
          val passWord = binding.textInputPassword.editText?.text.toString()
  
          val x = context?.let { UserDatabase.getDatabase(it).userDao() }
  
          val y = x?.readAllData(name,passWord)
  
          binding.buttonIngresar.setOnClickListener {
  
              if (y != null) {
                  findNavController().navigate(R.id.action_mainFragment_to_candidatesFragment)
  
              } else {
                  Toast.makeText(context, &quot;User does not exist&quot;, Toast.LENGTH_SHORT).show()
              }
  
          }
  
      }
  </code></pre>