Need examples of simple username and password auth...

1,899 views
Skip to first unread message

Gary Regan

unread,
Mar 4, 2015, 12:46:58 AM3/4/15
to go...@googlegroups.com

2015/03/03 22:43:27 connect: failed to connect to "127.0.0.1:9042": authentication required (using "org.apache.cassandra.auth.PasswordAuthenticator")

Session error no connections were made when creating the session

<nil>

panic: runtime error: invalid memory address or nil pointer dereference

panic: runtime error: invalid memory address or nil pointer dereference

[signal 0xb code=0x1 addr=0x0 pc=0x78f63]


Ben Hood

unread,
Mar 4, 2015, 1:34:02 AM3/4/15
to Gary Regan, go...@googlegroups.com
Hi Gary,

Your post(s) appear to have been truncated - could you restate the
issue that you are running into in a way that we can see what is going
on please?

Thanks,

Ben
> --
> You received this message because you are subscribed to the Google Groups
> "gocql" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to gocql+un...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

Gary Regan

unread,
Mar 4, 2015, 5:46:31 PM3/4/15
to go...@googlegroups.com, greg...@gmail.com
I was looking for examples on how to code simple username and password auth.
I have attached the simple code as a starting point...

// test project main.go
package main

import (
    "fmt"
    "github.com/gocql/gocql"
)

func main() {
    

    cluster := gocql.NewCluster("127.0.0.1")
    cluster.Keyspace = "mykeyspace"

    session, err := cluster.CreateSession()
    fmt.Println("Session error ", err)
    fmt.Println(session)

    defer session.Close()

    var user_name, address, city, password, phone, state, zip string

    if err := session.Query("SELECT user_name, address, city, password, phone, state, zip FROM users").Scan(&user_name, &address, &city, &password, &phone, &state, &zip); err != nil {
        fmt.Println("Err in query  ", err)
    }
    fmt.Println(user_name, "  ", address, "  ", city)
}


I have also attached a part of the .yaml file

# - AllowAllAuthenticator performs no checks - set it to disable authentication.
# - PasswordAuthenticator relies on username/password pairs to authenticate
# users. It keeps usernames and hashed passwords in system_auth.credentials table.
# Please increase system_auth keyspace replication factor if you use this authenticator.
authenticator: PasswordAuthenticator

# Authorization backend, implementing IAuthorizer; used to limit access/provide permissions
# Out of the box, Cassandra provides org.apache.cassandra.auth.{AllowAllAuthorizer,
# CassandraAuthorizer}.
#
# - AllowAllAuthorizer allows any action to any user - set it to disable authorization.
# - CassandraAuthorizer stores permissions in system_auth.permissions table. Please
# increase system_auth keyspace replication factor if you use this authorizer.
authorizer: CassandraAuthorizer


thanks ....

Ben Hood

unread,
Mar 5, 2015, 12:50:47 AM3/5/15
to Gary Regan, go...@googlegroups.com
After you create the cluster instance, add the password authentication like so:

cluster := gocql.NewCluster("127.0.0.1")
cluster.Authenticator = PasswordAuthenticator{
Username: "foo",
Password: "bar",

jve...@gmail.com

unread,
May 17, 2016, 2:46:19 PM5/17/16
to gocql, greg...@gmail.com
I get 'undefined: PasswordAuthenticator' if i remove the cluster.Authenticator line then it builds correctly. I made sure I imported "github.com/gocql/gocql". Why is it not recognizing PasswordAuthnticator?

min...@gmail.com

unread,
Nov 23, 2016, 8:19:25 AM11/23/16
to gocql
Use gocql.PasswordAuthnticator instead
Reply all
Reply to author
Forward
0 new messages