Please help me with creation of a password via a subroutine

So I edited a basic keypad code from here: http://www.circuitstoday.com/digital-code-lock-using-arduino and I tried to add the option to change the password by adding a subroutine which would check which key was pressed and would return the value. Whenever Press the key to change the password the correct message is displayed but I am unable to change the password. I don`t have much experience with C++, could anyone of you guys help me with this?

Subroutine

int Keypressvalue(){
  int vr;
  vr = 0;
  digitalWrite(r1,LOW);
  digitalWrite(r2,HIGH);
  digitalWrite(r3,HIGH);
  digitalWrite(r4,HIGH);
  colm1=digitalRead(c1);
  colm2=digitalRead(c2);
  colm3=digitalRead(c3);
  colm4=digitalRead(c4);
  if(colm1==LOW)
  { vr = 1;
    return vr;
    Serial.println("1P");
   delay(200);}
  else
  {
   if(colm2==LOW)
   { vr = 2;
     return vr;
     Serial.println("2P");
    delay(200);}
   else
   {
   if(colm3==LOW)
   {Serial.println("3P");
     vr = 3;
     return vr;
   delay(200);}
   else
   {}
   }}
  digitalWrite(r1,HIGH);
  digitalWrite(r2,LOW);
  digitalWrite(r3,HIGH);
  digitalWrite(r4,HIGH);
  colm1=digitalRead(c1);
  colm2=digitalRead(c2);
  colm3=digitalRead(c3);
  colm4=digitalRead(c4);
  if(colm1==LOW)
  {Serial.println("4P");
   vr = 4;
   return vr;
  delay(200);}
  else
  {
   if(colm2==LOW)
   {Serial.println("5P");
    vr = 5;
    return vr;
  delay(200);}
   else
   {
   if(colm3==LOW)
   {Serial.println("6P");
      vr = 6;
      return vr; 
    delay(200);}
   else
   {}
  digitalWrite(r1,HIGH);
  digitalWrite(r2,HIGH);
  digitalWrite(r3,LOW);
  digitalWrite(r4,HIGH);
  colm1=digitalRead(c1);
  colm2=digitalRead(c2);
  colm3=digitalRead(c3);
  colm4=digitalRead(c4);
  if(colm1==LOW)
  { vr = 7;
    return vr;
    Serial.println("7P");
   delay(200);}
  else
  {
   if(colm2==LOW)
   { vr = 8;
     return vr;
     Serial.println("8P");
    delay(200);}
   else
   {
   if(colm3==LOW)
   {Serial.println("9P");
     vr = 9;
     return vr;
   delay(200);}
   else{}
   }}}}}

Reference to subroutine:

if(colm1==LOW)
  {Serial.println("LOCKED");
    digitalWrite(lock,LOW);  //locks
    i=0;
    delay(200);}
   if(colm2==LOW)
   { if(c[0]==p[0]&&c[1]==p[1]&&c[2]==p[2]&&c[3]==p[3]&&c[4]==p[4]&&c[5]==p[5])
    {
    Serial.println("SETTING NEW PASSWORD, USE NUMBERS BETWEEN 1 AND 9");
    p[0] = Keypressvalue();
    p[1] = Keypressvalue();
    p[2] = Keypressvalue();
    p[3] = Keypressvalue();
    p[4] = Keypressvalue();
    p[5] = Keypressvalue();
    }
    }
   else
   {}

Whole Code:

int p[6]; //array for storing the password
int c[6]; // array for storing the input code
int n;
int a=0;
int i=0;
int lock=3;
int r1=6;
int r2=7;
int r3=8;
int r4=9;
int c1=10;
int c2=11;
int c3=12;
int c4=13;
int colm1;
int colm2;
int colm3;
int colm4;

void setup()
{
  
  pinMode(r1,OUTPUT);
  pinMode(r2,OUTPUT);
  pinMode(r3,OUTPUT);
  pinMode(r4,OUTPUT);
  pinMode(c1,INPUT);
  pinMode(c2,INPUT);
  pinMode(c3,INPUT);
  pinMode(c4,INPUT);
  pinMode(lock,OUTPUT);
  Serial.begin(9600);   //sets the baud rate at 9600
  digitalWrite(c1,HIGH);
  digitalWrite(c2,HIGH);
  digitalWrite(c3,HIGH);
  digitalWrite(c4,HIGH);
  digitalWrite(lock,LOW);
  p[0]=1;   //sets 1st digit of the password
  p[1]=2;  // sets 2nd digit of the password
  p[2]=3;  // sets 3rd digit of the password
  p[3]=4;  // sets 4th digit of the password
  p[4]=5;  // sets 5th digit of the password
  p[5]=6;  // sets 6th digit of the password
}
 //returns value of button pressed
  int Keypressvalue(){
  int vr;
  vr = 0;
  digitalWrite(r1,LOW);
  digitalWrite(r2,HIGH);
  digitalWrite(r3,HIGH);
  digitalWrite(r4,HIGH);
  colm1=digitalRead(c1);
  colm2=digitalRead(c2);
  colm3=digitalRead(c3);
  colm4=digitalRead(c4);
  if(colm1==LOW)
  { vr = 1;
    return vr;
    Serial.println("1P");
   delay(200);}
  else
  {
   if(colm2==LOW)
   { vr = 2;
     return vr;
     Serial.println("2P");
    delay(200);}
   else
   {
   if(colm3==LOW)
   {Serial.println("3P");
     vr = 3;
     return vr;
   delay(200);}
   else
   {}
   }}
  digitalWrite(r1,HIGH);
  digitalWrite(r2,LOW);
  digitalWrite(r3,HIGH);
  digitalWrite(r4,HIGH);
  colm1=digitalRead(c1);
  colm2=digitalRead(c2);
  colm3=digitalRead(c3);
  colm4=digitalRead(c4);
  if(colm1==LOW)
  {Serial.println("4P");
   vr = 4;
   return vr;
  delay(200);}
  else
  {
   if(colm2==LOW)
   {Serial.println("5P");
    vr = 5;
    return vr;
  delay(200);}
   else
   {
   if(colm3==LOW)
   {Serial.println("6P");
      vr = 6;
      return vr; 
    delay(200);}
   else
   {}
  digitalWrite(r1,HIGH);
  digitalWrite(r2,HIGH);
  digitalWrite(r3,LOW);
  digitalWrite(r4,HIGH);
  colm1=digitalRead(c1);
  colm2=digitalRead(c2);
  colm3=digitalRead(c3);
  colm4=digitalRead(c4);
  if(colm1==LOW)
  { vr = 7;
    return vr;
    Serial.println("7P");
   delay(200);}
  else
  {
   if(colm2==LOW)
   { vr = 8;
     return vr;
     Serial.println("8P");
    delay(200);}
   else
   {
   if(colm3==LOW)
   {Serial.println("9P");
     vr = 9;
     return vr;
   delay(200);}
   else{}
   }}}}}
void loop()
{
  digitalWrite(r1,LOW);
  digitalWrite(r2,HIGH);
  digitalWrite(r3,HIGH);
  digitalWrite(r4,HIGH);
  colm1=digitalRead(c1);
  colm2=digitalRead(c2);
  colm3=digitalRead(c3);
  colm4=digitalRead(c4);
  if(colm1==LOW)
  { n=1;
    a=1;
    Serial.println("1");
   delay(200);}
  else
  {
   if(colm2==LOW)
   { n=2;
     a=1;
     Serial.println("2");
    delay(200);}
   else
   {
   if(colm3==LOW)
   {Serial.println("3");
     n=3;
     a=1;
   delay(200);}
   else
   {
   if(colm4==LOW)
   {Serial.println("LOCKED");
    digitalWrite(lock,LOW);  //locks
    i=0;
    delay(200);}
   }}}
   
  digitalWrite(r1,HIGH);
  digitalWrite(r2,HIGH);
  digitalWrite(r3,LOW);
  digitalWrite(r4,HIGH);
  colm1=digitalRead(c1);
  colm2=digitalRead(c2);
  colm3=digitalRead(c3);
  colm4=digitalRead(c4);
  if(colm1==LOW)
  { n=7;
    a=1;
    Serial.println("7");
   delay(200);}
  else
  {
   if(colm2==LOW)
   { n=8;
     a=1;
     Serial.println("8");
    delay(200);}
   else
   {
   if(colm3==LOW)
   {Serial.println("9");
     n=9;
     a=1;
   delay(200);}
   else
   {}}
  digitalWrite(r1,HIGH);
  digitalWrite(r2,HIGH);
  digitalWrite(r3,HIGH);
  digitalWrite(r4,LOW);
  colm1=digitalRead(c1);
  colm2=digitalRead(c2);
  colm3=digitalRead(c3);
  colm4=digitalRead(c4);
  if(colm1==LOW)
  {Serial.println("LOCKED");
    digitalWrite(lock,LOW);  //locks
    i=0;
    delay(200);}
   if(colm2==LOW)
   { if(c[0]==p[0]&&c[1]==p[1]&&c[2]==p[2]&&c[3]==p[3]&&c[4]==p[4]&&c[5]==p[5])
    {
    Serial.println("SETTING NEW PASSWORD, USE NUMBERS BETWEEN 1 AND 9");
    p[0] = Keypressvalue();
    p[1] = Keypressvalue();
    p[2] = Keypressvalue();
    p[3] = Keypressvalue();
    p[4] = Keypressvalue();
    p[5] = Keypressvalue();
    }
    }
   else
   {}
    
   if(colm3==LOW)
   {
    if(c[0]==p[0]&&c[1]==p[1]&&c[2]==p[2]&&c[3]==p[3]&&c[4]==p[4]&&c[5]==p[5])
    {digitalWrite(lock,HIGH);  //unlocks
     Serial.println("UNLOCKED");
    c[5]=9;}       //corrupts the code in array c
    else
   {Serial.println("WRONG PASSWORD");}
   delay(200);}
   else
   {}

  digitalWrite(r1,HIGH);
  digitalWrite(r2,LOW);
  digitalWrite(r3,HIGH);
  digitalWrite(r4,HIGH);
  colm1=digitalRead(c1);
  colm2=digitalRead(c2);
  colm3=digitalRead(c3);
  colm4=digitalRead(c4);
  if(colm1==LOW)
  {Serial.println("4");
   n=4;
   a=1;
  delay(200);}
  else
  {
   if(colm2==LOW)
   {Serial.println("5");
    n=5;
    a=1;
  delay(200);}
   else
   {
   if(colm3==LOW)
   {Serial.println("6");
      n=6;
      a=1;
    delay(200);}
   else
   {
   if(colm4==LOW)
   {
    if(c[0]==p[0]&&c[1]==p[1]&&c[2]==p[2]&&c[3]==p[3]&&c[4]==p[4]&&c[5]==p[5])
    {digitalWrite(lock,HIGH);  //unlocks
     Serial.println("UNLOCKED");
    c[5]=9;}       //corrupts the code in array c
    else
   {Serial.println("WRONG PASSWORD");}
   delay(200);}
   }}}
    if(a==1) // test whether a digit key is pressed
    {
    c[i]=n; // saves the current digit pressed to array c
    i=i+1;
    a=0;}
   }}
{ vr = 1;
    return vr;
    Serial.println("1P");

Why have a print after a return?

Why not use the popular Keypad library instead of scanning the keypad yourself?

    p[0] = Keypressvalue();
    p[1] = Keypressvalue();
    p[2] = Keypressvalue();
    p[3] = Keypressvalue();
    p[4] = Keypressvalue();
    p[5] = Keypressvalue();

As noted above, you have code after the return statements in Keypressvalue() which will never run.

Not yet noted was your delay 200 is also after the return so that is never executed.

Think about how fast the Arduino is going to set those p0-p5 values....